Opened 10 years ago

Closed 10 years ago

Last modified 6 years ago

#8126 closed (fixed)

admin.autodiscover() fails on bogus INSTALLED_APPS entries

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

Description (last modified by Jacob)

Update: the real issue is that bogus entries in INSTALLED_APPS don't fail so well. Original ticket follows. —JKM

Revision 8185: Everything works fine.

8186 and current revision (8219) won't work unless I comment out admin.autodiscover(). There actually was a bug with one of my's, but now that's been fixed - the problem remains. I can import all my's from the shell just fine.

In fact, I even tried removing all my files. But admin.autodiscover() still kills everything. Traceback is not helpful:

 Request URL:
Django Version: 1.0-alpha-SVN-8219
Python Version: 2.5.2
Installed Applications:
Installed Middleware:

File "/usr/lib/python2.5/site-packages/django/core/handlers/" in get_response
  78.                     request.path_info)
File "/usr/lib/python2.5/site-packages/django/core/" in resolve
  238.             for pattern in self.urlconf_module.urlpatterns:
File "/usr/lib/python2.5/site-packages/django/core/" in _get_urlconf_module
  262.                 raise ImproperlyConfigured, "Error while importing URLconf %r: %s" % (self.urlconf_name, e)

Exception Type: ImproperlyConfigured at /projects/
Exception Value: Error while importing URLconf 'collab.urls': 'module' object has no attribute '__path__'


Attachments (1)

r8520-admin-autodiscover.patch (544 bytes) - added by Ivan Giuliani 10 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 10 years ago by Karen Tracey <kmtracey@…>

Resolution: worksforme
Status: newclosed

This has got to be caused by something specific to your setup, because plenty of people (well, at least me) are running on revs >= [8186] without error. I've followed up on your mailing list thread with an idea for narrowing down what the problem is, let's try to deal with it on the mailing list until/if it's determined that there's actually a bug in Django code.

comment:2 Changed 10 years ago by Beetle_B

Thought I might as well post the results here as well in case anyone else, one day, has this problem.

As per suggestion on django-users, I tried running admin.autodiscover from the shell. The output:

/usr/lib/python2.5/site-packages/django/contrib/admin/ in autodiscover()
     13     for app in settings.INSTALLED_APPS:
     14         try:
---> 15             imp.find_module("admin", __import__(app, {}, {}, [app.split(".")[-1]]).__path__)
     16         except ImportError:
     17             # there is no app, skip it

AttributeError: 'module' object has no attribute '__path__'

comment:3 Changed 10 years ago by Beetle_B

Resolution: worksforme
Status: closedreopened

From django-users:

OK, that's Django code. Go ahead and re-open the ticket I closed worksforme
with that info and details of what exactly you've got in INSTALLED_APPS

My traceback in the original ticket summary shows my INSTALLED_APPS. However, I'm sure that's not much help to you. What information do you need?

Do note that this error occurs even with no files (or rather, after I delete all of them).

comment:4 Changed 10 years ago by Jacob

Yeah, admin.autodiscover is being far too clever here.

comment:5 Changed 10 years ago by Beetle_B

OK. I narrowed it down. I commented out most of the apps and tried admin.autodiscover() from the shell. Apparently django.core.mail is the culprit - it's in my apps. Apparently I put it there long ago for django-registration, although I'm not sure it needs to be there.

I take it this is my error?

comment:6 Changed 10 years ago by Alex Gaynor

django.core.mail definitely doesn't need to be there, and that's almost definitely causing the problem.

comment:7 Changed 10 years ago by Beetle_B

Resolution: invalid
Status: reopenedclosed

comment:8 Changed 10 years ago by Karen Tracey <kmtracey@…>

Resolution: invalid
Status: closedreopened

Even if it's a user error, couldn't that line of code in autodiscover() be a bit smarter? I suppose we could all learn that "'module' object has no attribute '__path__'" means "check INSTALLED_APPS for bogus entries" but I'm reopening the ticket to see if the admin code here can't be improved a least raise a more helpful error message?

comment:9 Changed 10 years ago by Jacob

Description: modified (diff)
Summary: revision 8186 killed my admin. Commenting out admin.autodiscover() "works".admin.autodiscover() fails on bogus INSTALLED_APPS entries

(updated ticket with real reason)

comment:10 Changed 10 years ago by Jacob

Component: UncategorizedAdmin interface
milestone: 1.0
Owner: changed from nobody to Jacob
Status: reopenednew
Triage Stage: UnreviewedAccepted

Changed 10 years ago by Ivan Giuliani

comment:11 Changed 10 years ago by Ivan Giuliani

Has patch: set

The patch I provided fixes this issue, but I'm not sure this is the RightWay to fix this.

comment:12 Changed 10 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [8583]) Fixed #8126: improved admin.autodiscover() to be more forgiving of invalid INSTALLED_APPS entries and/or exotic import schemes that don't have __path__.

comment:13 Changed 8 years ago by ozgurodabasi@…

when I remove 'django.core.paginator' from installed apps, everything goes well

comment:14 Changed 6 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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