Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25381 closed Bug (invalid)

"default_app_config" causes custom commands to not be found

Reported by: Greg Ziegan Owned by: nobody
Component: Core (Management commands) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Not entirely sure if this is just an environment issue but I've been able to reproduce it with my current setup several times. You can look at my app's structure here:
https://github.com/anovelmous-dev-squad/anovelmous

When I comment out where default_app_config is set in the app's init.py, all my custom commands can be found again.
https://github.com/anovelmous-dev-squad/anovelmous/blob/master/anovelmous_app/__init__.py

Change History (7)

comment:1 by Tim Graham, 9 years ago

It looks like you have set AppConfig.name incorrectly. It points to 'api' but the Python path for that app appears to be 'anovelmous_app'.

comment:2 by Tim Graham, 9 years ago

Resolution: invalid
Status: newclosed

in reply to:  1 comment:3 by Greg Ziegan, 9 years ago

Replying to timgraham:

It looks like you have set AppConfig.name incorrectly. It points to 'api' but the Python path for that app appears to be 'anovelmous_app'.

When I change the name property to "anovelmous_app", I receive a LookupError.
LookupError: App 'anovelmous_app' doesn't have a 'Token' model.

I originally tried this setup to no avail, and it looked incorrect from the start. I need access to a database model on initialization that is defined in the api package. It works as expected when supplying "api" to the name property, except when looking for django commands.

comment:4 by Tim Graham, 9 years ago

Okay, but that doesn't look like a bug in Django. Please see TicketClosingReasons/UseSupportChannels for ways to get help.

I will however propose a documentation patch which might help you understand why things aren't working as you expect.

  • docs/ref/applications.txt

    diff --git a/docs/ref/applications.txt b/docs/ref/applications.txt
    index eb3cc6f..d634e73 100644
    a b Methods  
    204204
    205205.. method:: AppConfig.get_models()
    206206
    207     Returns an iterable of :class:`~django.db.models.Model` classes.
     207    Returns an iterable of :class:`~django.db.models.Model` classes for this
     208    application.
    208209
    209210.. method:: AppConfig.get_model(model_name)
    210211
    211212    Returns the :class:`~django.db.models.Model` with the given
    212     ``model_name``. Raises :exc:`LookupError` if no such model exists.
    213     ``model_name`` is case-insensitive.
     213    ``model_name``. Raises :exc:`LookupError` if no such model exists in this
     214    application. ``model_name`` is case-insensitive.
    214215
    215216.. method:: AppConfig.ready()
    216217

in reply to:  4 comment:5 by Greg Ziegan, 9 years ago

Replying to timgraham:

Okay, but that doesn't look like a bug in Django. Please see TicketClosingReasons/UseSupportChannels for ways to get help.

I will however propose a documentation patch which might help you understand why things aren't working as you expect.

  • docs/ref/applications.txt

    diff --git a/docs/ref/applications.txt b/docs/ref/applications.txt
    index eb3cc6f..d634e73 100644
    a b Methods  
    204204
    205205.. method:: AppConfig.get_models()
    206206
    207     Returns an iterable of :class:`~django.db.models.Model` classes.
     207    Returns an iterable of :class:`~django.db.models.Model` classes for this
     208    application.
    208209
    209210.. method:: AppConfig.get_model(model_name)
    210211
    211212    Returns the :class:`~django.db.models.Model` with the given
    212     ``model_name``. Raises :exc:`LookupError` if no such model exists.
    213     ``model_name`` is case-insensitive.
     213    ``model_name``. Raises :exc:`LookupError` if no such model exists in this
     214    application. ``model_name`` is case-insensitive.
    214215
    215216.. method:: AppConfig.ready()
    216217

Thank you, I ended up moving the AppConfig over to the other package and listed it in INSTALLED_APPS, resolving my issue. The documentation change does help clarify the issue.

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

In e7e8d30:

Refs #25381 -- Clarified that AppConfig model methods search only the current app.

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

In 95c00c4:

[1.8.x] Refs #25381 -- Clarified that AppConfig model methods search only the current app.

Backport of e7e8d30cae9457339eb49ae8584e82ff0a038e99 from master

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