From 9386512a832064404016143c57b523bb919da1c6 Mon Sep 17 00:00:00 2001 From: Robert Raposa Date: Thu, 21 Nov 2024 12:20:29 -0500 Subject: [PATCH] fix: bug when CODE_OWNER_MAPPINGS not defined No code_owner custom attributes should be added when CODE_OWNER_MAPPINGS is not defined. There was a bug in both the code and the unit tests. This has been fixed. --- CHANGELOG.rst | 6 ++++++ edx_django_utils/__init__.py | 2 +- edx_django_utils/monitoring/internal/code_owner/utils.py | 4 +++- .../monitoring/tests/code_owner/test_middleware.py | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 091e24d1..0d5c6528 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,12 @@ Change Log .. There should always be an "Unreleased" section for changes pending release. +7.0.1 - 2024-11-21 +------------------ +Fixed +~~~~~ +* Fix bug where code owner custom attributes were being defined, even when the CODE_OWNER_MAPPINGS setting was not defined. + 7.0.0 - 2024-10-16 ------------------ Removed diff --git a/edx_django_utils/__init__.py b/edx_django_utils/__init__.py index 512bddfd..7eaec0c2 100644 --- a/edx_django_utils/__init__.py +++ b/edx_django_utils/__init__.py @@ -2,7 +2,7 @@ EdX utilities for Django Application development.. """ -__version__ = "7.0.0" +__version__ = "7.0.1" default_app_config = ( "edx_django_utils.apps.EdxDjangoUtilsConfig" diff --git a/edx_django_utils/monitoring/internal/code_owner/utils.py b/edx_django_utils/monitoring/internal/code_owner/utils.py index b8a108c0..f927238a 100644 --- a/edx_django_utils/monitoring/internal/code_owner/utils.py +++ b/edx_django_utils/monitoring/internal/code_owner/utils.py @@ -88,7 +88,9 @@ def get_code_owner_mappings(): # .. setting_description: Used for monitoring and reporting of ownership. Use a # dict with keys of code owner name and value as a list of dotted path # module names owned by the code owner. - code_owner_mappings = getattr(settings, 'CODE_OWNER_MAPPINGS', {}) + code_owner_mappings = getattr(settings, 'CODE_OWNER_MAPPINGS', None) + if code_owner_mappings is None: + return None try: for code_owner in code_owner_mappings: diff --git a/edx_django_utils/monitoring/tests/code_owner/test_middleware.py b/edx_django_utils/monitoring/tests/code_owner/test_middleware.py index aad9e2a2..23d8ea50 100644 --- a/edx_django_utils/monitoring/tests/code_owner/test_middleware.py +++ b/edx_django_utils/monitoring/tests/code_owner/test_middleware.py @@ -231,13 +231,13 @@ def test_code_owner_transaction_mapping_error(self, mock_newrelic_agent, mock_se mock_set_custom_attribute, has_path_error=True, has_transaction_error=True ) - @patch('edx_django_utils.monitoring.internal.code_owner.utils.set_custom_attribute') + @patch('edx_django_utils.monitoring.internal.code_owner.middleware.set_custom_attribute') def test_code_owner_no_mappings(self, mock_set_custom_attribute): request = RequestFactory().get('/test/') self.middleware(request) mock_set_custom_attribute.assert_not_called() - @patch('edx_django_utils.monitoring.internal.code_owner.utils.set_custom_attribute') + @patch('edx_django_utils.monitoring.internal.code_owner.middleware.set_custom_attribute') def test_code_owner_transaction_no_mappings(self, mock_set_custom_attribute): request = RequestFactory().get('/bad/path/') self.middleware(request)