[Django] #30871: override_settings() does not restore partially deleted settings

3 views
Skip to first unread message

Django

unread,
Oct 11, 2019, 3:18:49 AM10/11/19
to django-...@googlegroups.com
#30871: override_settings() does not restore partially deleted settings
---------------------------------------------+------------------------
Reporter: Hodossy, Szabolcs | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/30871>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 11, 2019, 4:48:19 AM10/11/19
to django-...@googlegroups.com
#30871: override_settings() does not restore partially deleted settings.
-----------------------------------+--------------------------------------

Reporter: Hodossy, Szabolcs | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: master
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by felixxm):

* status: new => closed
* version: 2.2 => master
* resolution: => invalid


Comment:

Thanks for this report, however it is not a valid usage of the
`override_settings()` decorator (see
[https://docs.djangoproject.com/en/dev/topics/testing/tools/#django.test.override_settings
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/30871#comment:1>

Reply all
Reply to author
Forward
0 new messages