Changed behaviour of middlewares after 
|Reported by:||Petr Marhoun <petr.marhoun@…>||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Unlike the process_request() and process_view() methods, the process_response() method is always called, even if the process_request() and process_view() methods of the same middleware class were skipped because an earlier middleware method returned an HttpResponse.
But after  response middleware are called only if there is no response from process_request or process_view or process_exception or Http404 or PermissionDenied.
It is problematic with transaction middleware - it is necessary to call process_response or process_exception to close open transaction. But if process_response returns response, transaction is still opened and stacked. And if there is something outside transaction in the following request in the same thread, it is not committed - for example session middleware could be outside, it would be impossible to login.
I also found one bug in my code - if process_exception returns response, following exception middlewares are skipped and transaction could be closed in ThreadMiddleware.process_response. So there was commit, not rollback (before ). It was logical consequence of the documentation, but maybe there could be a note about it.
Change History (3)
comment:1 Changed 4 years ago by kmike
- Cc kmike added
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset