summaryrefslogtreecommitdiff
path: root/django/contrib/admin/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/contrib/admin/__init__.py')
-rw-r--r--django/contrib/admin/__init__.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/django/contrib/admin/__init__.py b/django/contrib/admin/__init__.py
index 8396ffc6b3..bb856a1241 100644
--- a/django/contrib/admin/__init__.py
+++ b/django/contrib/admin/__init__.py
@@ -2,12 +2,26 @@ from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
from django.contrib.admin.options import StackedInline, TabularInline
from django.contrib.admin.sites import AdminSite, site
+# 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():
"""
- Auto-discover INSTALLED_APPS admin.py modules and fail silently when
+ Auto-discover INSTALLED_APPS admin.py modules and fail silently when
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 imp
from django.conf import settings
@@ -38,3 +52,5 @@ def autodiscover():
# Step 3: import the app's admin file. If this has errors we want them
# to bubble up.
__import__("%s.admin" % app)
+ # autodiscover was successful, reset loading flag.
+ LOADING = False