Code

#19784 closed Bug (duplicate)

Custom urlconf reset too early

Reported by: pakal 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)

Attachments (0)

Change History (3)

comment:1 Changed 14 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Isn't that the same problem as #19541?

comment:2 Changed 14 months ago by carljm

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

comment:3 Changed 14 months ago by carljm

  • Resolution set to duplicate
  • Status changed from new to closed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.