From 7d9de178e724573c1326ee2c2bf4f0b8b15b6c62 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 10 Jan 2010 18:48:08 +0000 Subject: [PATCH] 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 --- django/core/handlers/base.py | 16 +++++++++------- .../middleware_exceptions/tests.py | 6 ++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index 034c1ceaa14..d735cd7cc59 100644 --- a/django/core/handlers/base.py +++ b/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) diff --git a/tests/regressiontests/middleware_exceptions/tests.py b/tests/regressiontests/middleware_exceptions/tests.py index 2f950a0c4a2..00c7d8b59f2 100644 --- a/tests/regressiontests/middleware_exceptions/tests.py +++ b/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):