Ticket #18824: 18824-1.diff

File 18824-1.diff, 1.9 KB (added by claudep, 3 years ago)

UserSettingsHolder keeping track of deleted settings

  • django/conf/__init__.py

    diff --git a/django/conf/__init__.py b/django/conf/__init__.py
    index 35f4ec8..f4d17ca 100644
    a b class UserSettingsHolder(BaseSettings): 
    152152        Requests for configuration variables not in this class are satisfied
    153153        from the module specified in default_settings (if possible).
    154154        """
     155        self.__dict__['_deleted'] = set()
    155156        self.default_settings = default_settings
    156157
    157158    def __getattr__(self, name):
     159        if name in self._deleted:
     160            raise AttributeError
    158161        return getattr(self.default_settings, name)
    159162
     163    def __setattr__(self, name, value):
     164        self._deleted.discard(name)
     165        return super(UserSettingsHolder, self).__setattr__(name, value)
     166
     167    def __delattr__(self, name):
     168        self._deleted.add(name)
     169        return super(UserSettingsHolder, self).__delattr__(name)
     170
    160171    def __dir__(self):
    161172        return list(self.__dict__) + dir(self.default_settings)
    162173
  • tests/regressiontests/settings_tests/tests.py

    diff --git a/tests/regressiontests/settings_tests/tests.py b/tests/regressiontests/settings_tests/tests.py
    index ffcb79e..7225fb0 100644
    a b class SettingsTests(TestCase): 
    148148    def test_settings_delete_wrapped(self):
    149149        self.assertRaises(TypeError, delattr, settings, '_wrapped')
    150150
     151    def test_override_settings_delete(self):
     152        """
     153        Allow deletion of a setting in an overriden settings set (#18824)
     154        """
     155        previous_i18n = settings.USE_I18N
     156        with self.settings(USE_I18N=False):
     157            del settings.USE_I18N
     158            self.assertRaises(AttributeError, getattr, settings, 'USE_I18N')
     159        self.assertEqual(settings.USE_I18N, previous_i18n)
     160
    151161    def test_allowed_include_roots_string(self):
    152162        """
    153163        ALLOWED_INCLUDE_ROOTS is not allowed to be incorrectly set to a string
Back to Top