mirror of
https://github.com/django/django.git
synced 2024-12-23 09:36:06 +00:00
[1.7.x] Also allowed a non-overridden setting to be deleted
Refs #20032, #18824. Thanks ztorstri at gmail.com for the report.
Backport of 3417ba0309
from master.
This commit is contained in:
parent
d9f8cc12ae
commit
a6eda3a5fc
@ -153,11 +153,12 @@ class UserSettingsHolder(BaseSettings):
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
self._deleted.discard(name)
|
||||
return super(UserSettingsHolder, self).__setattr__(name, value)
|
||||
super(UserSettingsHolder, self).__setattr__(name, value)
|
||||
|
||||
def __delattr__(self, name):
|
||||
self._deleted.add(name)
|
||||
return super(UserSettingsHolder, self).__delattr__(name)
|
||||
if hasattr(self, name):
|
||||
super(UserSettingsHolder, self).__delattr__(name)
|
||||
|
||||
def __dir__(self):
|
||||
return list(self.__dict__) + dir(self.default_settings)
|
||||
|
@ -1193,6 +1193,11 @@ have been overridden, like this::
|
||||
del settings.LOGIN_URL
|
||||
...
|
||||
|
||||
.. versionchanged:: 1.7
|
||||
|
||||
Previously, you could only simulate the deletion of a setting which was
|
||||
explicitely overridden.
|
||||
|
||||
When overriding settings, make sure to handle the cases in which your app's
|
||||
code uses a cache or similar feature that retains state even if the setting is
|
||||
changed. Django provides the :data:`django.test.signals.setting_changed`
|
||||
|
@ -232,10 +232,15 @@ class SettingsTests(TestCase):
|
||||
Allow deletion of a setting in an overridden settings set (#18824)
|
||||
"""
|
||||
previous_i18n = settings.USE_I18N
|
||||
previous_l10n = settings.USE_L10N
|
||||
with self.settings(USE_I18N=False):
|
||||
del settings.USE_I18N
|
||||
self.assertRaises(AttributeError, getattr, settings, 'USE_I18N')
|
||||
# Should also work for a non-overridden setting
|
||||
del settings.USE_L10N
|
||||
self.assertRaises(AttributeError, getattr, settings, 'USE_L10N')
|
||||
self.assertEqual(settings.USE_I18N, previous_i18n)
|
||||
self.assertEqual(settings.USE_L10N, previous_l10n)
|
||||
|
||||
def test_override_settings_nested(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user