Closed lucaswiman closed 9 years ago
Looks great!
Please add you to AUTHORS...
Added to AUTHORS in c60c9c805510a8fb6b055cb915df9c0f1d271718. Should I update the changelog as well?
Repository health decreased by 0.13% when pulling c60c9c8 on lucaswiman:master into d3f784f on jedie:master.
Should I update the changelog as well?
I will do this
@jedie This pull request updates the
ThreadLocal
middleware so that the thread local reference to therequest
object is cleared when the response is processed by the middleware.Issue Description
This is unlikely to matter in practice since a server will overwrite the previous
_thread_locals.request
when it receives a new request.The use case this is intended to fix is:
f()
is used on both the front end and back end of an application.get_current_{request,user}
is called, it creates a model entry with a foreign key referencing the change the user made.M
is created, or theUser
foreign key is NULL._thread_locals.request
variable. TheUser
object is created as part of the test, then destroyed when the database transaction is rolled back by thetearDown
method.Changes
ThreadLocalMiddleware.process_response
method, which is part of the Django middleware API: https://docs.djangoproject.com/en/1.8/topics/http/middleware/#process-response This method clears therequest
variable if it is defined.ThreadLocal
module's documentation.Testing
I added two views to the example app. One that returns the GET parameters from the current request, and one that simply raises an exception. I added tests that assert:
get_current_request
actually returns the current request). This passed on the master branch, and is just included for completeness.request
reference is cleared. This failed using the code on the master branch.raise_exception
view), therequest
reference is cleared. This failed using the code on the master branch.Thanks for maintaining this library!