Code

Opened 17 months ago

Closed 9 months ago

#19724 closed Bug (fixed)

manage.py app commands enumeration fails silently when MEDIA_URL doesn't end with a slash

Reported by: peter.davis8@… Owned by: nobody
Component: Core (Management commands) Version: 1.5-beta-1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

When the MEDIA_URL setting in settings.py does not contain a forward slash at the end, calling manage.py without arguments will result in only django core commands being displayed, but no application commands (as specified in INSTALLED_APPS) are shown.

This is presumably due to the parsing of the settings.py file failing silently on the incorrect MEDIA_URL setting. Although it is explicitly called out within the settings.py file (within comments above the MEDIA_URL setting), having it fail loudly when running manage.py is potentially a more expected behaviour.

Attachments (1)

19724-1.diff (851 bytes) - added by claudep 17 months ago.
Ouptut error message on sys.stderr if settings contain errors

Download all attachments as: .zip

Change History (10)

comment:1 Changed 17 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I can reproduce the problem and I think it's caused by:

        try:
            apps = settings.INSTALLED_APPS
        except ImproperlyConfigured:
            # Still useful for commands that do not require functional settings,
            # like startproject or help
            apps = []

in django.core.management.get_commands, as an invalid MEDIA_URL raises ImproperlyConfigured when the settings are first accessed.

comment:2 Changed 17 months ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

Changed 17 months ago by claudep

Ouptut error message on sys.stderr if settings contain errors

comment:3 Changed 17 months ago by claudep

  • Has patch set

comment:4 Changed 17 months ago by julien

  • Triage Stage changed from Accepted to Ready for checkin

That looks great to me! Just one nitpicky comment: it'd be useful to emphasize the causality between the two statements:

Project settings contain errors: <ERROR>
As a result, only the core Django commands are available.

comment:5 Changed 17 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 40ca99097f34b2180b2afe6d0056cade4c732618:

Fixed #19724 -- Output error when settings are improperly configured

...during retrieval of available management commands.
Thanks Peter Davis for the report and Julien Phalip for the review.

comment:6 Changed 17 months ago by Claude Paroz <claude@…>

In 2edef932ff4ffc766c7abe18bde2cc77babd8fef:

Revert "Fixed #19724 -- Output error when settings are improperly configured"

This reverts commit 40ca99097f34b2180b2afe6d0056cade4c732618.
Outputting error is not always suitable, for example this shouldn't
happen for the 'startproject' command.

comment:7 Changed 17 months ago by claudep

  • Resolution fixed deleted
  • Status changed from closed to new

The patch was not good.
For example, when running django-admin.py startproject, accessing settings.INSTALLED_APPS will always raise ImproperlyConfigured and this is the regular behaviour (no errors should be shown).

comment:8 Changed 17 months ago by claudep

  • Patch needs improvement set
  • Triage Stage changed from Ready for checkin to Accepted

comment:9 Changed 9 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In a098bee1b9fa4df64f3fd72ff5cbae43bf27e539:

Fixed #19724 -- Output note when showing only core management commands

When listing available management commands, only core commands are
listed if settings have any error. This commit adds a note in this
case so errors are not totally silently skipped.
Thanks Peter Davis for the report.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.