Django

Code

Ticket #8126 (closed: fixed)

Opened 4 months ago

Last modified 3 months ago

admin.autodiscover() fails on bogus INSTALLED_APPS entries

Reported by: Beetle_B Assigned to: jacob
Milestone: 1.0 Component: django.contrib.admin
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

r8520-admin-autodiscover.patch (0.5 kB) - added by kratorius on 08/24/08 11:45:30.

Change History

08/05/08 15:38:21 changed by Karen Tracey <kmtracey@gmail.com>

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to worksforme.
  • needs_tests changed.
  • needs_docs changed.

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.

08/05/08 15:41:08 changed 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__'

08/05/08 15:50:08 changed by Beetle_B

  • status changed from closed to reopened.
  • resolution deleted.

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

08/05/08 15:56:27 changed by jacob

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

08/05/08 16:03:25 changed 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?

08/05/08 16:04:53 changed by Alex

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

08/05/08 16:07:07 changed by Beetle_B

  • status changed from reopened to closed.
  • resolution set to invalid.

08/05/08 16:15:02 changed by Karen Tracey <kmtracey@gmail.com>

  • status changed from closed to reopened.
  • resolution deleted.

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?

08/12/08 12:00:48 changed by jacob

  • description changed.
  • 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)

08/12/08 12:01:09 changed by jacob

  • owner changed from nobody to jacob.
  • status changed from reopened to new.
  • stage changed from Unreviewed to Accepted.
  • component changed from Uncategorized to Admin interface.
  • milestone set to 1.0.

08/24/08 11:45:30 changed by kratorius

  • attachment r8520-admin-autodiscover.patch added.

08/24/08 11:47:11 changed by kratorius

  • has_patch set to 1.

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

08/26/08 11:18:27 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

(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__.


Add/Change #8126 (admin.autodiscover() fails on bogus INSTALLED_APPS entries)




Change Properties
Action