Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#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)

__init__.py.patch (578 bytes ) - added by Adrian Ribao 16 years ago.
django/contrib/admin/init.py modified

Download all attachments as: .zip

Change History (13)

comment:1 by Julien Phalip, 16 years ago

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.

comment:2 by Adrian Ribao, 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 Malcolm Tredinnick, 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 Adrian Ribao, 16 years ago

The problem lies in changeset [8583], I'll try to find out what's the problem.

by Adrian Ribao, 16 years ago

Attachment: __init__.py.patch added

django/contrib/admin/init.py modified

comment:5 by Adrian Ribao, 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.

in reply to:  5 comment:6 by Karen Tracey <kmtracey@…>, 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 Adrian Ribao, 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.

comment:8 by Adrian Ribao, 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.

in reply to:  8 ; comment:9 by Karen Tracey <kmtracey@…>, 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.

in reply to:  9 comment:10 by Adrian Ribao, 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 Malcolm Tredinnick, 16 years ago

Resolution: invalid
Status: newclosed

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.

comment:12 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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