Opened 6 years ago

Closed 6 years ago

#29236 closed Bug (fixed)

diffsettings raises misleading exception message if using settings.configure()

Reported by: Keryn Knight Owned by: Hasan Ramezani
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: Keryn Knight Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

If, rather than using the env var DJANGO_SETTINGS_MODULE one uses settings.configure(...), attempting to call diffsettings can fail because it calls settings._setup() unconditionally, with the exception

django.core.exceptions.ImproperlyConfigured: Requested settings, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

were the call instead:

if not settings.configured:
    settings._setup()

things would work correctly.

Change History (8)

comment:1 by Keryn Knight, 6 years ago

Cc: Keryn Knight added

comment:2 by Tim Graham, 6 years ago

Summary: diffsettings raises misleading exception message if using settings.configurediffsettings raises misleading exception message if using settings.configure()
Triage Stage: UnreviewedAccepted

comment:3 by Chris Mark, 6 years ago

Owner: changed from nobody to Chris Mark
Status: newassigned

comment:4 by Chris Mark, 6 years ago

Has patch: set
Needs tests: set

comment:5 by Chris Mark, 6 years ago

Keryn I found it difficult to add a test for the patch, since I cannot find a proper way to create the environment needed to catch this case.

On https://github.com/django/django/blob/master/tests/admin_scripts/tests.py#L2166, the tests use a target settings file, and if it is not present the tests will fail, so I need to configure somehow the settings, before(?) executing the actual command.

Any proposal or insight?

Chris

comment:6 by Hasan Ramezani, 6 years ago

Owner: changed from Chris Mark to Hasan Ramezani

comment:7 by Hasan Ramezani, 6 years ago

Needs tests: unset
Last edited 6 years ago by Tim Graham (previous) (diff)

comment:8 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 49b6793:

Fixed #29236 -- Fixed diffsettings crash if using settings.configure().

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