Opened 3 months ago

Closed 3 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 Jacob Walls, 3 months ago

Type: UncategorizedCleanup/optimization

If this fails with an ImproperlyConfigured or an ImportError exception ... the exception is completely swallowed.

The PR for ticket:32915 avoids catching ImportError, but makes no changes to ImproperlyConfigured, so we may choose to treat this as a dupe and leave feedback on ticket:32915 to treat both the same way (introspect whether ImproperlyConfigured emanated from a settings module before deciding to swallow it).

comment:2 by Natalia Bidart, 3 months ago

Resolution: duplicate
Status: newclosed
Type: Cleanup/optimizationBug
Version: 5.1dev

Thank you Lily for your ticket report, and thank you Jacob for your triage.

I agree this could be closed as a dupe of #32915. Other tangentially related tickets could be #25510 and #25523.

Note: See TracTickets for help on using tickets.
Back to Top