Opened 7 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 , 7 years ago
Cc: | added |
---|
comment:2 by , 7 years ago
Summary: | diffsettings raises misleading exception message if using settings.configure → diffsettings raises misleading exception message if using settings.configure() |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 7 years ago
Has patch: | set |
---|---|
Needs tests: | set |
comment:5 by , 7 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 , 6 years ago
Owner: | changed from | to
---|
https://github.com/django/django/pull/9812