Opened 11 years ago

Closed 11 years ago

#19784 closed Bug (duplicate)

Custom urlconf reset too early

Reported by: pascal chambon Owned by: nobody
Component: Core (URLs) Version: 1.4
Severity: Normal Keywords: urlconf request
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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)

Change History (3)

comment:1 by Aymeric Augustin, 11 years ago

Isn't that the same problem as #19541?

comment:2 by Carl Meyer, 11 years ago

Thanks for the report; closing as duplicate of #19541.

comment:3 by Carl Meyer, 11 years ago

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top