Opened 5 years ago

Closed 5 years ago

#30871 closed Bug (invalid)

override_settings() does not restore partially deleted settings.

Reported by: Hodossy, Szabolcs Owned by: nobody
Component: Testing framework Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When a settings is a dictionary, and only a key in that dicitonary needs to be deleted for a test, the @override_settings() decorator does not restore the original settings value.

It is a common practice for apps to use a single settings dictionary for their own configuration. A quick example can be seen here with the django-auth-adfs package: https://github.com/hodossy/django-auth-adfs at commit e11eca87ef96a3a074fc0846feb71183182e53dd.

To reproduce the issue, you can clone the project, install dependecies and run 'python manage.py test' to see test failing with KeyError due to above error.

Change History (1)

comment:1 by Mariusz Felisiak, 5 years ago

Resolution: invalid
Status: newclosed
Summary: override_settings() does not restore partially deleted settingsoverride_settings() does not restore partially deleted settings.
Version: 2.2master

Thanks for this report, however it is not a valid usage of the override_settings() decorator (see documentation). You can simulate the absence of a setting, but you cannot modify it partially with override_settings(). You should rather create a local copy and override the setting e.g.

    def test_access_callback_azure(self):
        ...
        auth_adfs_setting = settings.AUTH_ADFS.copy()
        del auth_adfs_setting["SERVER"]
        with self.settings(AUTH_ADFS=auth_adfs_setting):
             ...

Closing per TicketClosingReasons/UseSupportChannels.

Note: See TracTickets for help on using tickets.
Back to Top