Opened 10 years ago

Closed 9 years ago

#24776 closed Cleanup/optimization (fixed)

apps.get_app_config() could give better errors on fully-qualified package names

Reported by: Peter Inglesby Owned by: nobody
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Running eg ./manage.py dumpdata django.contrib.auth fails with CommandError: Unknown application: django.contrib.auth. Instead, you need to call the command with just auth.

This is because it calls through to apps.get_app_config which does not expect a fully-qualified package name.

There is a similar problem with other management commands that take an app's name.

There are a handful of approaches to fixing this:

  1. apps.get_app_config should split a package name on dots, throw away all but the last token, and use this for looking up the app. I've not thought through all the consequences of this -- could an app name legitimately contain dots?
  2. As for 1, but only if the package name begins django.contrib.
  3. When apps.get_app_config raises a LookupError, it could check to see whether its argument contains dots, and its message could be something like No installed app with label 'x.y.z'. Did you mean 'z'?.
  4. Whenever a management command calls apps.get_app_config, it could strip off django.contrib. if present.

I'm happy to code up a fix if/when the right approach is settle on.

Change History (3)

comment:1 by Aymeric Augustin, 10 years ago

These commands are documented to take app labels in argument rather than app names.

Option 3 is a decent idea but it should be implemented by inspecting the app cache to figure out if there's an app with the provided name and find its label. This cannot be done simply by splitting on dots because it's possible to give any label to an app with a customized AppConfig class.

comment:2 by Tim Graham, 9 years ago

Component: UncategorizedCore (Other)
Summary: apps.get_app_config does not handle fully-qualified package namesapps.get_app_config() could give better errors on fully-qualified package names
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization
Version: 1.8master

comment:3 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 0688a794:

Fixed #24776 -- Improved apps.get_app_config() error message on fully-qualified package names.

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