Django

Code

Ticket #6718 (closed: fixed)

Opened 9 months ago

Last modified 6 months ago

ImportError at /admin/logout/

Reported by: Eric B <ebartels@gmail.com> Assigned to: nobody
Milestone: 1.0 alpha Component: Contrib apps
Version: newforms-admin Keywords: auth importerror logout nfa-blocker
Cc: post@belahausmann.name Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description

I'm getting an ImportError? at /admin/logout/

Traceback:
File "/home/mrmelve/dev/python-local/django/core/handlers/base.py" in get_response
  82.                 response = callback(request, *callback_args, **callback_kwargs)
File "/home/mrmelve/dev/python-local/django/contrib/admin/sites.py" in root
  113.             return self.logout(request)
File "/home/mrmelve/dev/python-local/django/contrib/admin/sites.py" in logout
  197.         from django.contrib.auth.views import logout
File "/home/mrmelve/dev/python-local/django/contrib/auth/views.py" in <module>
  1. from django.contrib.auth.forms import AuthenticationForm
File "/home/mrmelve/dev/python-local/django/contrib/auth/forms.py" in <module>
  1. from django.contrib.auth.models import User
File "/home/mrmelve/dev/python-local/django/contrib/auth/models.py" in <module>
  369. from django.contrib.auth import admin
File "/home/mrmelve/dev/python-local/django/contrib/auth/admin.py" in <module>
  1. from django.contrib.auth.forms import UserCreationForm

Exception Type: ImportError at /admin/logout/
Exception Value: cannot import name UserCreationForm

This looks like a circular import problem in contrib.auth.admin. From the traceback, importing User imports admin which imports UserCreationForm? which imports User again. Oddly, I haven't experienced this error using the development server, but only when running under mod_python. Also, the problem is somewhat intermittent in that sometimes the logout completes without a problem, but most of the time triggers the import error.

I've attached a patch which avoids the problem by moving the import of UserCreationForm? from the top level into the add_view method.

Attachments

logout_importerror.diff (0.7 kB) - added by Eric B <ebartels@gmail.com> on 03/04/08 18:41:51.

Change History

03/04/08 18:41:51 changed by Eric B <ebartels@gmail.com>

  • attachment logout_importerror.diff added.

03/05/08 09:51:11 changed by jacob

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

03/15/08 16:27:11 changed by Bela Hausmann <post@belahausmann.name>

  • cc set to post@belahausmann.name.

04/01/08 23:56:44 changed by Mnewman

  • needs_better_patch set to 1.

I believe this error is due to an AlreadyRegistered? exception and it will be fixed when that is handled differently. That being said if it is the AlreadyRegistered? exception, this patch is really not the way to fix it. Also, I am only able to duplicate this in mod_python; in the runserver environment it doesn't seem to through the error. I think that this error and some other odd AlreadyRegistered? errors are due to the way mod_python handles imports.

04/09/08 16:40:48 changed by mariarchi

It also happens to me when I'm trying to log in (mod_python, worker mpm). Also, why this ticket is not marked as nfa-blocker?

05/27/08 20:20:35 changed by mrts

  • keywords changed from auth importerror logout to auth importerror logout nfa-blocker.

Marking as nfa-blocker. This clearly needs to be fixed one way or other before nfa can be merged.

06/16/08 10:49:08 changed by garcia_marc

  • milestone set to 1.0 alpha.

06/16/08 17:39:36 changed by brosner

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

(In [7671]) newforms-admin: Fixed #6718 -- Removed a circular import in contrib/auth/admin.py. Thanks Eric B.


Add/Change #6718 (ImportError at /admin/logout/)




Change Properties
Action