Opened 8 months ago

Closed 3 months 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: master
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 Changed 8 months ago by Keryn Knight

Cc: Keryn Knight added

comment:2 Changed 8 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 8 months ago by Chris Mark

Owner: changed from nobody to Chris Mark
Status: newassigned

comment:4 Changed 8 months ago by Chris Mark

Has patch: set
Needs tests: set

comment:5 Changed 8 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

comment:6 Changed 3 months ago by Hasan Ramezani

Owner: changed from Chris Mark to Hasan Ramezani

comment:7 Changed 3 months ago by Hasan Ramezani

Needs tests: unset
Last edited 3 months ago by Tim Graham (previous) (diff)

comment:8 Changed 3 months ago by Tim Graham <timograham@…>

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