Opened 19 years ago
Closed 18 years ago
#1812 closed defect (fixed)
[patch] django-admin sql <foo> gives exception when no model exists
Reported by: | Owned by: | Malcolm Tredinnick | |
---|---|---|---|
Component: | Core (Management commands) | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
hi.
I have a application which has no models in it.
when I run
django-admin.py sql text
it gives me the following exception.
Traceback (most recent call last): File "/usr/local/bin/django-admin.py", line 5, in ? management.execute_from_command_line() File "/magik/django/core/management.py", line 1195, in execute_from_command_line mod_list = [models.get_app(app_label) for app_label in args[1:]] File "/magik/django/db/models/loading.py", line 29, in get_app return __import__(app_name, '', '', ['models']).models AttributeError: 'module' object has no attribute 'models'
it should fail nicely.
Attachments (1)
Change History (10)
by , 19 years ago
Attachment: | loading-getapp.diff added |
---|
comment:1 by , 19 years ago
Summary: | django-admin sql <foo> gives exception when no model exists → [patch] django-admin sql <foo> gives exception when no model exists |
---|
Something like that?
comment:3 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [3201]) Fixes #1812 -- Added model validity checks to ensure that models.py exists, and has been successfully imported for all INSTALLED_APPS. Previous behaviour was to silently ignore empty/problem models, which resulted in the display of an admin page that doesn't display a supposedly installed model. Thanks to Ian Holsman for the original report.
comment:4 by , 18 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
There are cases when no models exist in an application and with r3201 its now fails on syncdb with such apps installed. Trivial fix to this is to bring back removed AttributeError exception handler:
--- django/db/models/loading.py (revision 3206) +++ django/db/models/loading.py (working copy) @@ -27,6 +27,8 @@ for app_name in settings.INSTALLED_APPS: try: load_app(app_name) + except AttributeError: + pass # This app doesn't have a models.py in it. except Exception, e: # Problem importing the app _app_errors[app_name] = e
comment:5 by , 18 years ago
I don't believe that change is in the right place -- i.e., it will have side effects.
comment:6 by , 18 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
I'm neck deep in that part of the code at the moment trying to sort out a few problems. I'll take care of this one. The proposed patch traps a few real errors, so isn't right. We can fix it at the source fairly easily.
comment:7 by , 18 years ago
This also affects people that have the zope page template exceptionformatter installed from http://www.zope.org/Members/shh/DjangoPageTemplates
comment:8 by , 18 years ago
Work around for the zope page templates exceptionformatter is of course to add an empty models.py to the exceptionformatter directory in django/contrib/
I have situations where multiple apps share models and some apps do not have their own model, these now all contain an empty models.py. But is this really required? Why can it not be possible to have apps without a models.py?
comment:9 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Add an ImproperlyConfigured exception when an app has no models module