Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#24801 closed Bug (invalid)

AppConfigs aren't loaded when the application is in a nested directory

Reported by: Josh Smeaton Owned by: nobody
Component: Core (Other) Version: dev
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


We had someone in IRC trying to use a custom AppConfig with an application that was installed to a subdirectory called "apps". The AppConfig wasn't being picked up, and the import_module machinery was throwing errors. I've replicated this locally too.

Application at: project/top/drill/

    'top.drill',  # with default_app_config 
    'top.drill.apps.DrillConfig',  # without default_app_config

$ ./ shell
Traceback (most recent call last):
  File "./", line 9, in <module>
  File "/vagrant/venv/lib/python3.3/site-packages/django/core/management/", line 427, in execute_from_command_line
  File "/vagrant/venv/lib/python3.3/site-packages/django/core/management/", line 391, in execute
  File "/vagrant/venv/lib/python3.3/site-packages/django/", line 21, in setup
  File "/vagrant/venv/lib/python3.3/site-packages/django/apps/", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/vagrant/venv/lib/python3.3/site-packages/django/apps/", line 137, in create
    app_module = import_module(app_name)
  File "/vagrant/venv/lib64/python3.3/importlib/", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1529, in _find_and_load_unlocked
ImportError: No module named 'drill'

Problem happens using default_app_config or by referencing the AppConfig from INSTALLED_APPS. I suspect there's a problem related to importing modules when the application isn't in the project root directory.

I think that was the same problem, but it was never fully investigated.

Attachments (1)

appconfig_24801.tar.gz (2.3 KB) - added by Josh Smeaton 7 years ago.
Test project demonstrating problem

Download all attachments as: .zip

Change History (8)

comment:1 Changed 7 years ago by Josh Smeaton

I should note that the same setup works when moving the application back to the project root directory (and updating paths to remove the "top" module part).

comment:2 Changed 7 years ago by Abhaya Agarwal

The error occurs when Django tries to import the module named in AppConfig. I suspect you have only drill specified there, just like #23470. The error will go away if the name in app config is changed to top.drill.

Perhaps documentation should be updated to explicitly say that the name in app config should match what we put in INSTALLED_APPS or that it should be importable?

comment:3 Changed 7 years ago by Carl Meyer

The documentation already seems pretty clear that should be the full Python dotted path to the app:

Josh, can you verify what the value of the name attribute in your AppConfig class for your test was?

Changed 7 years ago by Josh Smeaton

Attachment: appconfig_24801.tar.gz added

Test project demonstrating problem

comment:4 Changed 7 years ago by Josh Smeaton

Yep, sorry. It was the name attribute of the AppConfig causing the problem. Documentation is quite clear if you continue reading to the end of

comment:5 Changed 7 years ago by Josh Smeaton

Resolution: invalid
Status: newclosed

comment:6 Changed 7 years ago by Carl Meyer

I think something like path might be clearer than name for that attribute (name evokes something human-readable), but it's too late for bikeshedding those names now!

comment:7 Changed 7 years ago by Aymeric Augustin

path was already used to store the filesystem path to the package (when this concept makes sense).

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