summaryrefslogtreecommitdiff
path: root/django/contrib
diff options
context:
space:
mode:
authorBrian Rosner <brosner@gmail.com>2010-04-12 14:36:48 +0000
committerBrian Rosner <brosner@gmail.com>2010-04-12 14:36:48 +0000
commit2a752edd808921c1938fbd4ea3a07a76af9eb0f5 (patch)
treec44738a674f6e36d9b7583ec0eadd071566805a0 /django/contrib
parent2cebe4395e9ed345bbbe346b91842b4c97ffcfc7 (diff)
downloaddjango-2a752edd808921c1938fbd4ea3a07a76af9eb0f5.tar.gz
Fixed #11957 -- exceptions in admin.py are no longer hidden after second request
Before you had to restart runserver for the correct exception message to show up again. Reverts fix in r9680 which has this side-affect. Thanks to jarrow, carljm and ramiro for their work on the patch and tickets. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12956 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib')
-rw-r--r--django/contrib/admin/__init__.py26
1 files changed, 11 insertions, 15 deletions
diff --git a/django/contrib/admin/__init__.py b/django/contrib/admin/__init__.py
index abc5f09b56..92f23a90e6 100644
--- a/django/contrib/admin/__init__.py
+++ b/django/contrib/admin/__init__.py
@@ -4,9 +4,6 @@ from django.contrib.admin.options import StackedInline, TabularInline
from django.contrib.admin.sites import AdminSite, site
from django.utils.importlib import import_module
-# A flag to tell us if autodiscover is running. autodiscover will set this to
-# True while running, and False when it finishes.
-LOADING = False
def autodiscover():
"""
@@ -14,16 +11,8 @@ def autodiscover():
not present. This forces an import on them to register any admin bits they
may want.
"""
- # Bail out if autodiscover didn't finish loading from a previous call so
- # that we avoid running autodiscover again when the URLconf is loaded by
- # the exception handler to resolve the handler500 view. This prevents an
- # admin.py module with errors from re-registering models and raising a
- # spurious AlreadyRegistered exception (see #8245).
- global LOADING
- if LOADING:
- return
- LOADING = True
+ import copy
import imp
from django.conf import settings
@@ -54,6 +43,13 @@ def autodiscover():
# Step 3: import the app's admin file. If this has errors we want them
# to bubble up.
- import_module("%s.admin" % app)
- # autodiscover was successful, reset loading flag.
- LOADING = False
+ try:
+ before_import_registry = copy.copy(site._registry)
+ import_module('%s.admin' % app)
+ except:
+ # Reset the model registry to the state before the last import as
+ # this import will have to reoccur on the next request and this
+ # could raise NotRegistered and AlreadyRegistered exceptions
+ # (see #8245).
+ site._registry = before_import_registry
+ raise