#29467: override_settings context manager can leave undesired settings state
-------------------------------------+-------------------------------------
Reporter: Sławek | Owner: nobody
Ehlert |
Type: Bug | Status: new
Component: Testing | Version: 2.0
framework | Keywords: settings
Severity: Normal | override_settings
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When connecting to the {{{setting_changed}}} signal a receiver function
that throws an error, one can break the {{{override_settings}}}
decorator/context manager and leave the current settings in the modified
state. {{{override_settings}}} context manager should be more defensive
inside the "enter" part when the {{{setting_changed}}} signal is sent.
Example:
{{{
## settings
SETTING_A = 'A'
SETTING_B = 'B'
## usage
from django.test import override_settings
from django.conf import settings
from django.core import signals
def setting_changed_receiver(*args, **kwargs):
if kwargs['setting'] == 'SETTING_B':
raise Exception("I'm here for the lulz")
signals.setting_changed.connect(setting_changed_receiver)
try:
with override_settings(SETTING_A='X', SETTING_B='X'):
pass
except:
pass
print(settings.SETTING_A)
print(settings.SETTING_B)
}}}
prints out:
{{{
X
X
}}}
instead of the expected:
{{{
A
B
}}}
This may have some repercussions while running tests, since one failing
test can influence a different, unrelated one.
--
Ticket URL: <https://code.djangoproject.com/ticket/29467>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/048.545dd53277a72168ccb69dc1c21ff187%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.