From ac8da7b36f353ffc225ee27b0aeb96f8912b9362 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Sat, 12 Dec 2009 17:51:51 +0000 Subject: [PATCH] FIxed #10130: you may now delete attributes on `settings`. Thanks, jcassee. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11824 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/functional.py | 7 +++++++ tests/regressiontests/settings/__init__.py | 0 tests/regressiontests/settings/models.py | 0 tests/regressiontests/settings/tests.py | 17 +++++++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 tests/regressiontests/settings/__init__.py create mode 100644 tests/regressiontests/settings/models.py create mode 100644 tests/regressiontests/settings/tests.py diff --git a/django/utils/functional.py b/django/utils/functional.py index 434b6b76c9..823cda4587 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -277,6 +277,13 @@ class LazyObject(object): self._setup() setattr(self._wrapped, name, value) + def __delattr__(self, name): + if name == "_wrapped": + raise TypeError("can't delete _wrapped.") + if self._wrapped is None: + self._setup() + delattr(self._wrapped, name) + def _setup(self): """ Must be implemented by subclasses to initialise the wrapped object. diff --git a/tests/regressiontests/settings/__init__.py b/tests/regressiontests/settings/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/settings/models.py b/tests/regressiontests/settings/models.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/settings/tests.py b/tests/regressiontests/settings/tests.py new file mode 100644 index 0000000000..fa217b1d79 --- /dev/null +++ b/tests/regressiontests/settings/tests.py @@ -0,0 +1,17 @@ +import unittest +from django.conf import settings + +class SettingsTests(unittest.TestCase): + + # + # Regression tests for #10130: deleting settings. + # + + def test_settings_delete(self): + settings.TEST = 'test' + self.assertEqual('test', settings.TEST) + del settings.TEST + self.assertRaises(AttributeError, getattr, settings, 'TEST') + + def test_settings_delete_wrapped(self): + self.assertRaises(TypeError, delattr, settings, '_wrapped')