Opened 5 months ago
Closed 5 months ago
#36422 closed Bug (duplicate)
Settings exception hidden when running management command
| Reported by: | Lily Acorn | Owned by: | |
|---|---|---|---|
| Component: | Core (Management commands) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Lily Acorn | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
When running a management command, Django tries to load settings.INSTALLED_APPS (https://github.com/django/django/blob/ad28db666e0884b658f5e240c3d7ee1362688ba1/django/core/management/__init__.py#L381-L386). If this fails with an ImproperlyConfigured or an ImportError exception, Django saves this as self.settings_exception. This is used to output help text (https://github.com/django/django/blob/ad28db666e0884b658f5e240c3d7ee1362688ba1/django/core/management/__init__.py#L235-L242) when the subcommand is help or the --help or -h flag is set. Otherwise the exception is completely swallowed, which is really unhelpful for identifying the cause of later failures.
In my case, I was getting a chain of AppRegistryNotReady exceptions from the migrate subcommand, but the root cause of an ImproperlyConfigured exception from my settings was deeply hidden, until I did some fairly deep exploration with pdb.
A suggested fix is to add self.settings_exception to the exception chain when a later exception is raised.
Change History (2)
comment:1 by , 5 months ago
| Type: | Uncategorized → Cleanup/optimization |
|---|
comment:2 by , 5 months ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
| Type: | Cleanup/optimization → Bug |
| Version: | 5.1 → dev |
The PR for ticket:32915 avoids catching
ImportError, but makes no changes toImproperlyConfigured, so we may choose to treat this as a dupe and leave feedback on ticket:32915 to treat both the same way (introspect whetherImproperlyConfiguredemanated from a settings module before deciding to swallow it).