Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #18824 -- Allow deleting a setting from overriden settings

  • Loading branch information...
commit 22f85b9057825b5b4139abf5fd7e8c4ba0d16981 1 parent cc9b767
Claude Paroz authored September 04, 2012
11  django/conf/__init__.py
@@ -152,11 +152,22 @@ def __init__(self, default_settings):
152 152
         Requests for configuration variables not in this class are satisfied
153 153
         from the module specified in default_settings (if possible).
154 154
         """
  155
+        self.__dict__['_deleted'] = set()
155 156
         self.default_settings = default_settings
156 157
 
157 158
     def __getattr__(self, name):
  159
+        if name in self._deleted:
  160
+            raise AttributeError
158 161
         return getattr(self.default_settings, name)
159 162
 
  163
+    def __setattr__(self, name, value):
  164
+        self._deleted.discard(name)
  165
+        return super(UserSettingsHolder, self).__setattr__(name, value)
  166
+
  167
+    def __delattr__(self, name):
  168
+        self._deleted.add(name)
  169
+        return super(UserSettingsHolder, self).__delattr__(name)
  170
+
160 171
     def __dir__(self):
161 172
         return list(self.__dict__) + dir(self.default_settings)
162 173
 
10  tests/regressiontests/settings_tests/tests.py
@@ -148,6 +148,16 @@ def test_settings_delete(self):
148 148
     def test_settings_delete_wrapped(self):
149 149
         self.assertRaises(TypeError, delattr, settings, '_wrapped')
150 150
 
  151
+    def test_override_settings_delete(self):
  152
+        """
  153
+        Allow deletion of a setting in an overriden settings set (#18824)
  154
+        """
  155
+        previous_i18n = settings.USE_I18N
  156
+        with self.settings(USE_I18N=False):
  157
+            del settings.USE_I18N
  158
+            self.assertRaises(AttributeError, getattr, settings, 'USE_I18N')
  159
+        self.assertEqual(settings.USE_I18N, previous_i18n)
  160
+
151 161
     def test_allowed_include_roots_string(self):
152 162
         """
153 163
         ALLOWED_INCLUDE_ROOTS is not allowed to be incorrectly set to a string

0 notes on commit 22f85b9

Please sign in to comment.
Something went wrong with that request. Please try again.