Skip to content

Commit

Permalink
Also allowed a non-overridden setting to be deleted
Browse files Browse the repository at this point in the history
Refs #20032, django#18824. Thanks ztorstri at gmail.com for the report.
  • Loading branch information
claudep committed Apr 12, 2014
1 parent 3e3a737 commit 3417ba0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions django/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ def __getattr__(self, name):

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)
Expand Down
5 changes: 5 additions & 0 deletions docs/topics/testing/tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 5 additions & 0 deletions tests/settings_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,15 @@ def test_override_settings_delete(self):
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):
"""
Expand Down

0 comments on commit 3417ba0

Please sign in to comment.