#8596 closed (invalid)
Error while importing URLconf 'mysite.urls': No module named models
Reported by: | Adrian Ribao | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | 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
After upgrading to rev [8617], I get an error caused by:
admin.autodiscover()
The exception value is:
Error while importing URLconf 'mysite.urls': No module named models
I can't tell much more about it as the traceback is not useful.
The installed apps looks like:
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.sitemaps', 'blog',
I have tried with mysite.blog in INSTALLED_APPS but I get another error about importing.
Attachments (1)
Change History (13)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
The admin was working before the upgrading. I have 13 custom admin, and I have commented all the lines in each file and I'm still getting the same error.
comment:3 by , 16 years ago
So go back to a version that works, then go to something halfway in between and see if that works. If so, move forwards halfway again, otherwise move back halfway. After a few checkouts, you'll find the exact version that caused the breakage. That will be of some help in trying to work out where the problem lies.
comment:4 by , 16 years ago
The problem lies in changeset [8583], I'll try to find out what's the problem.
follow-up: 6 comment:5 by , 16 years ago
Has patch: | set |
---|
I have attached a patch. This just make the site work if there is some error making an import.
My site is working now but there is no admin interface for one of my apps. I think it must be a problem with namespaces but it's one of the most weird s things I have ever seen.
comment:6 by , 16 years ago
Replying to tolano:
I have attached a patch. This just make the site work if there is some error making an import.
My site is working now but there is no admin interface for one of my apps. I think it must be a problem with namespaces but it's one of the most weird s things I have ever seen.
The problem seems to be, then, that the import of the admin.py for this app is failing. Your patch simply ignores the error, which is not likely what Django wants to do. Try importing the admin.py file for this app from a manage.py shell prompt and see what is causing it to fail. That's the real problem that needs fixing.
comment:7 by , 16 years ago
The import is failing but the web should run anyway, so I think this patch is good enough, just to be prevented.
When you enter the admin and don't see the app there, you know there is a problem.
In my case the problem was that there were some files in the dir that shouldn't be there like: models.py.~1~ and so on. After deleting those files the app appeared in the admin again.
IMHO the patch should be there either failing silently or raising an exception. In the last case, the exception must be useful and well documented.
follow-up: 9 comment:8 by , 16 years ago
The import is failing but the web should run anyway, so I think this patch is good enough, just to be prevented.
When you enter the admin and don't see the app there, you know there is a problem.
In my case the problem was that there were some files in the dir that shouldn't be there like: models.py.~1~ and so on. After deleting those files the app appeared in the admin again.
IMHO the patch should be there either failing silently or raising an exception. In the last case, the exception must be useful and well documented.
follow-up: 10 comment:9 by , 16 years ago
Replying to tolano:
The import is failing but the web should run anyway, so I think this patch is good enough, just to be prevented.
Note the comment directly above where the patch adds except ImportError: continue
states: "Import errors here will (and should) bubble up," So it was a conscious decision to not ignore ImportErrors there, which the patch reverses (without altering the comment so resulting comment and code are in direct contradiction).
In my case the problem was that there were some files in the dir that shouldn't be there like: models.py.~1~ and so on. After deleting those files the app appeared in the admin again.
It might be nice to better understand what caused the error in your case, though it may be too late now. Certainly adding a file named models.py~1~ in one of my own app directories doesn't cause this problem.
IMHO the patch should be there either failing silently or raising an exception. In the last case, the exception must be useful and well documented.
The issue of the original exception traceback getting hidden is covered by #7524, I believe.
comment:10 by , 16 years ago
Replying to Karen Tracey <kmtracey@gmail.com>:
It might be nice to better understand what caused the error in your case, though it may be too late now. Certainly adding a file named models.py~1~ in one of my own app directories doesn't cause this problem.
I'm afraid it's too late, probably models.py.~1~ was a copy of models py, I didn't understand the problem either, just deleted the files to try and it worked. I should have looked inside before.
comment:11 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
This is a bug in your code. There's no responsibility for Django to "run anyway", since that would be hiding bugs and causing other problems further down the track. As Karen's mentioned, there's another ticket open for better exception reporting. Closing this one, since it's not a bug in Django.
Could you show the code of your custom
admin.py
files? It's likely that you're doing a wrong import in one of them.