Opened 4 months ago

Last modified 4 months ago

#29236 assigned Bug

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

Reported by: Keryn Knight Owned by: Chris Mark
Component: Core (Management commands) Version: master
Severity: Normal Keywords:
Cc: Keryn Knight Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes 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 (5)

comment:1 Changed 4 months ago by Keryn Knight

Cc: Keryn Knight added

comment:2 Changed 4 months ago by Tim Graham

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

comment:3 Changed 4 months ago by Chris Mark

Owner: changed from nobody to Chris Mark
Status: newassigned

comment:4 Changed 4 months ago by Chris Mark

Has patch: set
Needs tests: set

comment:5 Changed 4 months ago by Chris Mark

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

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