Opened 7 years ago
Closed 7 years ago
#28791 closed Cleanup/optimization (fixed)
ManagementUtility.execute() does not handle ImportError for invalid settings module
Reported by: | Marten Kenbeek | Owned by: | Hrishikesh Barman |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Hrishikesh Barman, Adam Johnson | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | yes | UI/UX: | no |
Description
In ManagementUtility.execute(), the code tries to load the settings, and catches ImproperlyConfigured
in case the settings aren't configured. However, if DJANGO_SETTINGS_MODULE
is set to an invalid module (e.g. from the previous project you were working on), an uncaught ImportError
is raised. This causes commands that don't need the settings, such as startproject
, to fail.
It seems to me that the ImportError
can safely be caught so that core commands that don't need settings can be executed. If the settings are accessed later on (either because the command can't be found or the command uses the settings), the ImportError
will be reraised.
Change History (9)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Cc: | added |
---|
comment:3 by , 7 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Bug → Cleanup/optimization |
comment:4 by , 7 years ago
Cc: | added |
---|
comment:5 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:6 by , 7 years ago
I've sent a pull request for this ticket,
https://github.com/django/django/pull/9367
It's failing a flake8 test, I ran the tests locally.
Please let me know about any further changes.
comment:7 by , 7 years ago
Has patch: | set |
---|---|
Needs tests: | set |
Patch needs improvement: | set |
comment:8 by , 7 years ago
The improved patch for this ticket is here: https://github.com/django/django/pull/9367
Hi Marten,
This seems like a valid enhancement to me. I reproduced the bug and is valid.
Can I start contributing to this?
I have a question, how do I test if my changes work? Do I have to install the cloned and modified django everytime I make a modification?
Also, how to go about writing tests for this?