Incorrect error from manage.py sql when app fails to load
|Reported by:||Glenn||Owned by:||nobody|
|Component:||Core (Management commands)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
./manage.py sql stomp Error: App with label stomp could not be found. Are you sure your INSTALLED_APPS setting is correct?
This is an incorrect error when the app is found but fails to import. The actual error is never displayed, which is hard to diagnose. If I add some diagnostics in django/db/models/loading.py load_app to print the exception, the problem becomes obvious:
./manage.py sqlall stomp cannot import name TestModel Error: App with label stomp could not be found. Are you sure your INSTALLED_APPS setting is correct?
It should probably just pass the exception up and show a trace. I've attached a patch to do this, but it causes errors when running some tests:
Error while importing humanize: File "./runtests.py", line 134, in django_tests mod = load_app(model_label) File "/home/glenn/django/django/db/models/loading.py", line 74, in load_app models = import_module('.models', app_name) File "/home/glenn/django/django/utils/importlib.py", line 35, in import_module __import__(name) ImportError: No module named models
for humanize, syndication, sitemaps, databrowse, admindocs and localflavor. Spying on runtests.py django_tests, these seem to be failing silently anyway; this is just making the "Error while importing" exception handler actually get called, where before they were silent. I'm not sure if there's another bug in there that this is exposing.
(Watch out: there's both eg. regressiontests.humanize and django.contrib.humanize for a few of those tests, and usually one of them works and the other doesn't.)
Change History (17)
Changed 7 years ago by Glenn
comment:1 Changed 7 years ago by Glenn
- Has patch unset
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
Changed 7 years ago by seveas
comment:3 Changed 7 years ago by seveas
- Component changed from Database layer (models, ORM) to django-admin.py
- Has patch set