django-configurations icon indicating copy to clipboard operation
django-configurations copied to clipboard

django-configurations is incompatible with `modify_settings` and `override_settings` decorators

Open posita opened this issue 3 years ago • 1 comments

# …/settings.py
from configurations import Configuration

class MyConfiguration(Configuration):
    DEBUG = False
    # …
# …/test_thing.py
from django.test import modify_settings

@modify_settings(DEBUG=True)
def test_settings():
    from django.conf import settings

    assert hasattr(settings, "DEBUG")
    assert settings.DEBUG

Running the above test will blow up here with the error TypeError: 'bool' object is not iterable. This makes sense, looking at the code:

            try:
                # When called from SimpleTestCase.setUpClass, values may be
                # overridden several times; cumulate changes.
                value = self.options[name]
            except KeyError:
                value = list(getattr(settings, name, []))  # <-- Boom!

In that context, getattr(settings, name, …) gets the value of MyConfiguration.DEBUG, which is False.

posita avatar May 20 '22 15:05 posita

That's a good find.

lino avatar Jul 18 '22 06:07 lino