Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 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 admin.py's, but now that's been fixed - the problem remains. I can import all my admin.py's from the shell just fine.

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

 Request URL: http://127.0.0.1:8000/projects/
Django Version: 1.0-alpha-SVN-8219
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.markup',
 'collab.registration',
 'django.core.mail',
 'django.contrib.admin',
 'collab.profiles',
 'collab.project',
 'collab.teleconference',
 'collab.action',
 'collab.issues']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'collab.collab_middleware.CheckProfileExistence',
 'collab.collab_middleware.RemoveAnonymousMessage')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  78.                     request.path_info)
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in resolve
  238.             for pattern in self.urlconf_module.urlpatterns:
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" 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__'

Ideas?

Attachments (1)

r8520-admin-autodiscover.patch (544 bytes) - added by kratorius 6 years ago.

Download all attachments as: .zip

Change History (15)

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

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 6 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/__init__.py 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 admin.py, skip it

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

comment:3 Changed 6 years ago by Beetle_B

  • Resolution worksforme deleted
  • Status changed from closed to reopened

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
please.

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 admin.py files (or rather, after I delete all of them).

comment:4 Changed 6 years ago by jacob

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

comment:5 Changed 6 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 6 years ago by Alex

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

comment:7 Changed 6 years ago by Beetle_B

  • Resolution set to invalid
  • Status changed from reopened to closed

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

  • Resolution invalid deleted
  • Status changed from closed to reopened

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 bit...at least raise a more helpful error message?

comment:9 Changed 6 years ago by jacob

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

(updated ticket with real reason)

comment:10 Changed 6 years ago by jacob

  • Component changed from Uncategorized to Admin interface
  • milestone set to 1.0
  • Owner changed from nobody to jacob
  • Status changed from reopened to new
  • Triage Stage changed from Unreviewed to Accepted

Changed 6 years ago by kratorius

comment:11 Changed 6 years ago by kratorius

  • 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 6 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

(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 4 years ago by ozgurodabasi@…

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

comment:14 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.