Ver Fonte

Fixed #6094 again -- fixed broken unit tests. Thanks, isagalaev

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12186 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Adrian Holovaty há 15 anos atrás
pai
commit
7d9de178e7

+ 9 - 7
django/core/handlers/base.py

@@ -72,13 +72,8 @@ class BaseHandler(object):
             try:
                 # Reset the urlconf for this thread.
                 urlresolvers.set_urlconf(None)
-
-                # Get urlconf from request object, if available.  Otherwise use default.
-                urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
-
-                # Set the urlconf for this thread to the one specified above.
-                urlresolvers.set_urlconf(urlconf)
-                resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
+                # Obtain a default resolver. It's needed early for handling 404's.
+                resolver = urlresolvers.RegexURLResolver(r'^/', None)
 
                 # Apply request middleware
                 for middleware_method in self._request_middleware:
@@ -86,6 +81,13 @@ class BaseHandler(object):
                     if response:
                         return response
 
+                # Get urlconf from request object, if available.  Otherwise use default.
+                urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
+                # Set the urlconf for this thread to the one specified above.
+                urlresolvers.set_urlconf(urlconf)
+                # Reset the resolver with a possibly new urlconf
+                resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
+
                 callback, callback_args, callback_kwargs = resolver.resolve(
                         request.path_info)
 

+ 2 - 4
tests/regressiontests/middleware_exceptions/tests.py

@@ -8,15 +8,13 @@ class RequestMiddleware(object):
         raise Exception('Exception')
 
 class MiddlewareExceptionTest(TestCase):
-    def __init__(self, *args, **kwargs):
-        super(MiddlewareExceptionTest, self).__init__(*args, **kwargs)
+    def setUp(self):
         self.exceptions = []
         got_request_exception.connect(self._on_request_exception)
-
-    def setUp(self):
         self.client.handler.load_middleware()
 
     def tearDown(self):
+        got_request_exception.disconnect(self._on_request_exception)
         self.exceptions = []
 
     def _on_request_exception(self, sender, request, **kwargs):