Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#20032 closed Cleanup/optimization (fixed)

Allow override_settings to delete settings

Reported by: coolRR Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


override_settings is used to change settings' values. Sometimes you want to delete a setting (not just set it to an empty value), and then have it restored later. override_settings should be able to do this, probably by using some kind of constant like DELETE_FROM_SETTINGS as the value given to it.

Change History (7)

comment:1 Changed 5 years ago by Claude Paroz

You can do that currently by deleting a setting when settings are overriden, something like:

def test_something(self):
    del settings.SOME_SETTING

Sufficient or not? A documentation issue?

comment:2 Changed 5 years ago by Jacob

Component: Testing frameworkDocumentation
Triage Stage: UnreviewedAccepted

Agreed - documentation is the way to go.

comment:3 Changed 5 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In 50eb70b08fae48445a52680b2d07a9535b25e3c5:

Fixed #20032 -- Documented how to simulate the absence of a setting

Thanks Ram Rachum for the report.

comment:4 Changed 4 years ago by ztorstri@…

I've read the documentation, and tried the approach above, but it doesn't work for me.

Unit test:

from django.test.utils import override_settings
from django.conf import settings

class SimpleTests(TestCase):

def test_simple_settings_removal(self):

del settings.STATIC_URL

Error thrown:

ERROR: test_simple_settings_removal (manager_core.tests.SimpleTests)

Traceback (most recent call last):

File "/projects/Shepherd/ShepherdEnvironment/local/lib/python2.7/site-packages/django/test/", line 249, in inner

return test_func(*args, kwargs)

File "/projects/Shepherd/zach_local_cluster/trunk/manager_core/", line 76, in test_simple_settings_removal

del settings.STATIC_URL

File "/projects/Shepherd/ShepherdEnvironment/local/lib/python2.7/site-packages/django/utils/", line 249, in delattr

delattr(self._wrapped, name)

File "/projects/Shepherd/ShepherdEnvironment/local/lib/python2.7/site-packages/django/conf/", line 193, in delattr

return super(UserSettingsHolder, self).delattr(name)

AttributeError: STATIC_URL

I always get attribute errors when I try to delete settings and use override_settings at the same time.

comment:5 Changed 4 years ago by Claude Paroz

You are right, this works only when the setting is actually mentionned inside the override_settings call. I'll fix this soon.

comment:6 Changed 4 years ago by Claude Paroz <claude@…>

In 3417ba03094b644f01597d6b5a43ccbc71a55378:

Also allowed a non-overridden setting to be deleted

Refs #20032, #18824. Thanks ztorstri at for the report.

comment:7 Changed 4 years ago by Claude Paroz <claude@…>

In a6eda3a5fc524333b476deed5057ee9803d91108:

[1.7.x] Also allowed a non-overridden setting to be deleted

Refs #20032, #18824. Thanks ztorstri at for the report.
Backport of 3417ba0309 from master.

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