#36422: Settings exception hidden when running management command
-------------------------------------+-------------------------------------
Reporter: Lily Acorn | Type:
| Uncategorized
Status: new | Component: Core
| (Management commands)
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36422>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.