Ticket #13090: 13090.1.diff
File 13090.1.diff, 3.7 KB (added by , 15 years ago) |
---|
-
django/core/handlers/base.py
70 70 71 71 try: 72 72 try: 73 # Reset the urlconffor this thread.74 url resolvers.set_urlconf(None)75 # Obtain a default resolver. It's needed early for handling 404's.76 resolver = urlresolvers.RegexURLResolver(r'^/', None)73 # Setup default url resolver for this thread. 74 urlconf = settings.ROOT_URLCONF 75 urlresolvers.set_urlconf(urlconf) 76 resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) 77 77 78 78 # Apply request middleware 79 79 for middleware_method in self._request_middleware: … … 81 81 if response: 82 82 return response 83 83 84 # Get urlconf from request object, if available. Otherwise use default. 85 urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF) 86 # Set the urlconf for this thread to the one specified above. 87 urlresolvers.set_urlconf(urlconf) 88 # Reset the resolver with a possibly new urlconf 89 resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) 84 if hasattr(request, "urlconf"): 85 # Reset url resolver with a custom urlconf. 86 urlconf = request.urlconf 87 urlresolvers.set_urlconf(urlconf) 88 resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) 90 89 91 90 callback, callback_args, callback_kwargs = resolver.resolve( 92 91 request.path_info) -
tests/regressiontests/middleware_exceptions/tests.py
3 3 from django.test import TestCase 4 4 from django.core.signals import got_request_exception 5 5 6 class RequestMiddleware(object):7 def process_request(self, request):8 raise Exception('Exception')9 6 10 class MiddlewareExceptionTest(TestCase): 11 def setUp(self): 12 self.exceptions = [] 13 got_request_exception.connect(self._on_request_exception) 14 self.client.handler.load_middleware() 7 class RequestException(Exception): 8 pass 15 9 16 def tearDown(self):17 got_request_exception.disconnect(self._on_request_exception)18 self.exceptions = []19 10 20 def _on_request_exception(self, sender, request, **kwargs): 21 self.exceptions.append(sys.exc_info()) 11 class RequestMiddleware(object): 12 def process_request(self, request): 13 raise RequestException('Exception') 22 14 15 16 class MiddlewareExceptionTest(TestCase): 23 17 def test_process_request(self): 18 self.client.handler.load_middleware() 24 19 self.client.handler._request_middleware.insert(0, RequestMiddleware().process_request) 25 try: 26 response = self.client.get('/') 27 except: 28 # Test client indefinitely re-raises any exceptions being raised 29 # during request handling. Hence actual testing that exception was 30 # properly handled is done by relying on got_request_exception 31 # signal being sent. 32 pass 33 self.assertEquals(len(self.exceptions), 1) 34 exception, value, tb = self.exceptions[0] 35 self.assertEquals(value.args, ('Exception', )) 20 self.assertRaises(RequestException, self.client.get, '/')