Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#8596 closed (invalid)

Error while importing URLconf 'mysite.urls': No module named models

Reported by: tolano Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 tolano 6 years ago.
django/contrib/admin/init.py modified

Download all attachments as: .zip

Change History (13)

comment:1 Changed 6 years ago by julien

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 6 years ago by tolano

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 Changed 6 years ago by mtredinnick

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 Changed 6 years ago by tolano

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

Changed 6 years ago by tolano

django/contrib/admin/init.py modified

comment:5 follow-up: Changed 6 years ago by tolano

  • 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 in reply to: ↑ 5 Changed 6 years ago by Karen Tracey <kmtracey@…>

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 Changed 6 years ago by tolano

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 follow-up: Changed 6 years ago by tolano

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:9 in reply to: ↑ 8 ; follow-up: Changed 6 years ago by Karen Tracey <kmtracey@…>

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 in reply to: ↑ 9 Changed 6 years ago by tolano

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 Changed 6 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from new to 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.

comment:12 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.