From 22f85b9057825b5b4139abf5fd7e8c4ba0d16981 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Tue, 4 Sep 2012 09:41:12 +0200 Subject: [PATCH] Fixed #18824 -- Allow deleting a setting from overriden settings --- django/conf/__init__.py | 11 +++++++++++ tests/regressiontests/settings_tests/tests.py | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/django/conf/__init__.py b/django/conf/__init__.py index 35f4ec8397..f4d17ca9f3 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -152,11 +152,22 @@ class UserSettingsHolder(BaseSettings): Requests for configuration variables not in this class are satisfied from the module specified in default_settings (if possible). """ + self.__dict__['_deleted'] = set() self.default_settings = default_settings def __getattr__(self, name): + if name in self._deleted: + raise AttributeError return getattr(self.default_settings, name) + def __setattr__(self, name, value): + self._deleted.discard(name) + return super(UserSettingsHolder, self).__setattr__(name, value) + + def __delattr__(self, name): + self._deleted.add(name) + return super(UserSettingsHolder, self).__delattr__(name) + def __dir__(self): return list(self.__dict__) + dir(self.default_settings) diff --git a/tests/regressiontests/settings_tests/tests.py b/tests/regressiontests/settings_tests/tests.py index ffcb79eb09..7225fb03ef 100644 --- a/tests/regressiontests/settings_tests/tests.py +++ b/tests/regressiontests/settings_tests/tests.py @@ -148,6 +148,16 @@ class SettingsTests(TestCase): def test_settings_delete_wrapped(self): self.assertRaises(TypeError, delattr, settings, '_wrapped') + def test_override_settings_delete(self): + """ + Allow deletion of a setting in an overriden settings set (#18824) + """ + previous_i18n = settings.USE_I18N + with self.settings(USE_I18N=False): + del settings.USE_I18N + self.assertRaises(AttributeError, getattr, settings, 'USE_I18N') + self.assertEqual(settings.USE_I18N, previous_i18n) + def test_allowed_include_roots_string(self): """ ALLOWED_INCLUDE_ROOTS is not allowed to be incorrectly set to a string