#7198 closed Bug (fixed)
improved error message on apps without models.py files
Reported by: | George Vilches | Owned by: | Justin Lilly |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | management command sql sqlall |
Cc: | sanfordarmstrong@…, johann@…, gabehr@…, noah@…, brianz@…, Jari Pennanen, omer.drow@…, hs@…, Silver_Ghost | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When attempting to run python manage.py sql <list_of_apps> (or sqlall, sqlindexes, etc.), if one of the apps listed does not have any models, the command will generate this error.
Error: App with label XXXXX could not be found. Are you sure your INSTALLED_APPS setting is correct?
The solution is to allow emptyOK=True when the models are pulled from each app. (Patch attached).
There are several reasons to create apps that have no models.py, not the least of which is to register more management commands with your project in their own independent app (which you could then include in several other projects). Someone trying to automate the use of the management commands to generate SQL would not be able to determine easily which apps do and do not have models.py, but it is not in any way harmful to just allow emptyOK=True, as all other app errors will still be caught, and the output does not change in any way before or after the patch.
Attachments (5)
Change History (38)
by , 17 years ago
Attachment: | sql_no_models_r7520.patch added |
---|
comment:1 by , 17 years ago
Needs documentation: | set |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 17 years ago
Needs documentation: | unset |
---|
I'm curious why you would mark this as needs_docs. There is no behavior necessary to document here for the management command, as it will work in all cases silently, and the behavior is no different than anything existing.
comment:4 by , 15 years ago
Cc: | added |
---|
comment:5 by , 15 years ago
this is a serious problem - afaik tinymce and filebrowser apps will trigger this.
comment:6 by , 15 years ago
ok disregard that.
this problem also happens if you have an import error in your models.py. i changed too much on a single go and incorrectly blamed the other apps - they do have their own models.py.
comment:7 by , 15 years ago
Has a decision been made on how to solve this bug?
I think you should be able to have no models in an app if you want, and still be able to use manage.py tools such as tests.
by , 15 years ago
Attachment: | sql_no_models_r11600.patch added |
---|
Updated the patch since it's been brought up again.
comment:8 by , 15 years ago
Cc: | added |
---|---|
Summary: | manage.py sql/sqlall/etc. errors on apps without models.py files → manage.py sql/sqlall/test/etc. errors on apps without models.py files |
I confirm that this patch (adding emptyOK=True) fixes the following error on Django 1.1, for a testapp without models.py:
./manage.py test testapp Traceback (most recent call last): File "./manage.py", line 18, in <module> execute_manager(settings) File "__init__.py", line 384, in execute_manager File "__init__.py", line 325, in execute File "common/zip-packages/django-1.1.zip/django/core/management/base.py", line 200, in run_from_argv File "common/zip-packages/django-1.1.zip/django/core/management/base.py", line 227, in execute File "common/zip-packages/django-1.1.zip/django/core/management/commands/test.py", line 23, in handle File "common/zip-packages/django-1.1.zip/django/test/simple.py", line 178, in run_tests File "common/zip-packages/django-1.1.zip/django/db/models/loading.py", line 125, in get_app django.core.exceptions.ImproperlyConfigured: App with label testapp could not be found
This error was reported as #3310 earlier but closed as a duplicate of this ticket.
comment:9 by , 15 years ago
I had the same problem. Another way around this issue, without having to modify any Django files, is to simply place an empty models.py file in the app directory.
comment:10 by , 15 years ago
since non-Django apps are de facto accepted since years, why not to respect this fact? ==> Let's allow emptyOK and let's skip not nice solution with injecting empty models.py
comment:11 by , 15 years ago
Cc: | added |
---|
At the very least, the error messages needs to point to the real issue. Reporting that "an app with that label could not be found" because there's no models.py file sends users on a wild goose chase that could take them hours or days to figure out. It's just bad behavior.
I don't care what the design decision ends up being, the error message needs to change.
comment:13 by , 15 years ago
Cc: | added |
---|
comment:14 by , 15 years ago
Cc: | added |
---|
comment:15 by , 14 years ago
Cc: | added |
---|
comment:16 by , 14 years ago
Cc: | added |
---|---|
Needs documentation: | set |
comment:17 by , 14 years ago
Unsetting needs documentation flag, per comment 2:
"I'm curious why you would mark this as needs_docs. There is no behavior necessary to document here for the management command, as it will work in all cases silently, and the behavior is no different than anything existing."
comment:18 by , 14 years ago
Needs documentation: | unset |
---|
comment:19 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:20 by , 14 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
comment:21 by , 14 years ago
UI/UX: | unset |
---|
I just recreated this bug. The fix of creating a blank models.py still works. This error is extremely misleading because the app is actually installed correctly in the settings.py and accessible. I couldn't believe that this is such an edge case to not get any attention over 4 years, but maybe this is just the case. BTW, I recreated this bug in 1.3.
comment:22 by , 14 years ago
Easy pickings: | set |
---|
Currently, the definition of a django application is: a package that contains a module named "models". For instance, see the note in https://docs.djangoproject.com/en/1.3/ref/settings/#installed-apps
I suppose this hasn't gotten much attention because people consider it's part of the learning curve of Django.
Gabriel Hurley, who is a core developer, proposed a solution in comment 11. You're welcome to propose a patch implementing it, then ask for a review on the mailing list.
However, if you want to lift the requirement that an app must contain a models.py file, you will have to check thoroughly the code and docs — the existence of this file is taken for granted in many places.
comment:23 by , 14 years ago
I just hit this error, too. I was trying to add tests to an existing app that is installed and is known to work, it just doesn't need models.
The test runner told me django.core.exceptions.ImproperlyConfigured: App with label pages could not be found
. I don't mind that the definition of an app is a package that contains a module named "models", but I think this error message could mention this fact so that people are pointed in the right direction.
comment:24 by , 13 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 13 years ago
Attachment: | sql_proper_err_msg.diff added |
---|
Creates proper error message for app without models.py module.
comment:25 by , 13 years ago
Cc: | added |
---|
comment:26 by , 13 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:29 by , 13 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
https://github.com/django/django/pull/39
Just updated wording, but seems otherwise reasonable. Taking over the ticket so we can have a name against it, rather than anonymous.
comment:30 by , 13 years ago
Summary: | manage.py sql/sqlall/test/etc. errors on apps without models.py files → improved error message on apps without models.py files |
---|---|
Triage Stage: | Design decision needed → Ready for checkin |
I think the DDN here was for the original proposal of not actually requiring the models.py. Just improving the error message is a no-brainer.
comment:32 by , 13 years ago
Easy pickings: | unset |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
Close, but no cigar.
First, the error message is missing the app_label
for string interpolation, so the error message is wrong.
Second, this absolutely needs a unit test. Unfortunately, that's very difficult due to the way the test runner loads test apps. In fact, it's incapable of loading a test app without a models.py file. So instead a test case can be dropped into a different app with a models.py file which can then attempt to load an app without a models.py file and catch the exception.
I'll attach a patch with both fixes momentarily for review.
by , 13 years ago
Attachment: | 7198_fix_with_tests.diff added |
---|
fixes string interpolation, adds tests (with improvements by carljm)
Patch to allow management commands against apps with no models, against r7520