Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

FIxed #10130: you may now delete attributes on `settings`. Thanks, jc…

…assee.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11824 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ac8da7b36f353ffc225ee27b0aeb96f8912b9362 1 parent f761802
Jacob Kaplan-Moss authored December 12, 2009
7  django/utils/functional.py
@@ -277,6 +277,13 @@ def __setattr__(self, name, value):
277 277
                 self._setup()
278 278
             setattr(self._wrapped, name, value)
279 279
 
  280
+    def __delattr__(self, name):
  281
+        if name == "_wrapped":
  282
+            raise TypeError("can't delete _wrapped.")
  283
+        if self._wrapped is None:
  284
+            self._setup()
  285
+        delattr(self._wrapped, name)
  286
+
280 287
     def _setup(self):
281 288
         """
282 289
         Must be implemented by subclasses to initialise the wrapped object.
0  tests/regressiontests/settings/__init__.py
No changes.
0  tests/regressiontests/settings/models.py
No changes.
17  tests/regressiontests/settings/tests.py
... ...
@@ -0,0 +1,17 @@
  1
+import unittest
  2
+from django.conf import settings
  3
+
  4
+class SettingsTests(unittest.TestCase):
  5
+
  6
+    #
  7
+    # Regression tests for #10130: deleting settings.
  8
+    #
  9
+
  10
+    def test_settings_delete(self):
  11
+        settings.TEST = 'test'
  12
+        self.assertEqual('test', settings.TEST)
  13
+        del settings.TEST
  14
+        self.assertRaises(AttributeError, getattr, settings, 'TEST')
  15
+
  16
+    def test_settings_delete_wrapped(self):
  17
+        self.assertRaises(TypeError, delattr, settings, '_wrapped')

0 notes on commit ac8da7b

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