Custom urlconf reset too early
|Reported by:||pascal chambon||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In core/handlers/base.py of django, the "cleanup" of customp urlconf, via a urlresolvers.set_urlconf(None),
happens BEFORE response processors are loaded.
That prevents any url resolution in response middlewares, especially it breaks django debug toolbar when it tries to regenerate the template contexts in my project.
I see no reason why response middlewares shouldn't have the same request context as the rest of request processing steps, so would it be possible to place the finally clause to the end, like that ?
try: # Apply response middleware, regardless of the response for middleware_method in self._response_middleware: response = middleware_method(request, response) response = self.apply_response_fixes(request, response) except: # Any exception should be gathered and handled signals.got_request_exception.send(sender=self.__class__, request=request) response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) return response finally: ### <<<<< PART PUSHED TO THE VERY END OF REQUEST HANDLING # Reset URLconf for this thread on the way out for complete # isolation of request.urlconf urlresolvers.set_urlconf(None)