mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
f761802b22
commit
ac8da7b36f
|
@ -277,6 +277,13 @@ class LazyObject(object):
|
||||||
self._setup()
|
self._setup()
|
||||||
setattr(self._wrapped, name, value)
|
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):
|
def _setup(self):
|
||||||
"""
|
"""
|
||||||
Must be implemented by subclasses to initialise the wrapped object.
|
Must be implemented by subclasses to initialise the wrapped object.
|
||||||
|
|
|
@ -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')
|
Loading…
Reference in New Issue