Author: brosner Date: 2010-04-12 09:55:45 -0500 (Mon, 12 Apr 2010) New Revision: 12957
Modified: django/branches/releases/1.1.X/django/contrib/admin/__init__.py django/branches/releases/1.1.X/tests/regressiontests/bug8245/tests.py Log: 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. Backport of r12956 from trunk. Modified: django/branches/releases/1.1.X/django/contrib/admin/__init__.py =================================================================== --- django/branches/releases/1.1.X/django/contrib/admin/__init__.py 2010-04-12 14:36:48 UTC (rev 12956) +++ django/branches/releases/1.1.X/django/contrib/admin/__init__.py 2010-04-12 14:55:45 UTC (rev 12957) @@ -4,9 +4,6 @@ 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 @@ 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 @@ -53,6 +42,13 @@ # 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 Modified: django/branches/releases/1.1.X/tests/regressiontests/bug8245/tests.py =================================================================== --- django/branches/releases/1.1.X/tests/regressiontests/bug8245/tests.py 2010-04-12 14:36:48 UTC (rev 12956) +++ django/branches/releases/1.1.X/tests/regressiontests/bug8245/tests.py 2010-04-12 14:55:45 UTC (rev 12957) @@ -18,6 +18,13 @@ else: self.fail( 'autodiscover should have raised a "Bad admin module" error.') - # Calling autodiscover again should bail out early and not raise an - # AlreadyRegistered error. - admin.autodiscover() + + # Calling autodiscover again should raise the very same error it did + # the first time, not an AlreadyRegistered error. + try: + admin.autodiscover() + except Exception, e: + self.failUnlessEqual(str(e), "Bad admin module") + else: + self.fail( + 'autodiscover should have raised a "Bad admin module" error.') -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.