Document when process_response and process_exception middleware is invoked
|Reported by:||TP||Owned by:||Jacob|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
It would be helpful if the django docs better covered the exact semantics of when middleware handlers are invoked. For example, if there's an exception will my custom middleware's process_exception hander be called? How about my process_response handler? This caused some subtle bugs on our website and I thought the docs could go into this more to help other people.
It turns out that django runs exception handlers specified in middleware until one of them returns a response or until django has executed every exception handler. This means your custom handler may or may not be invoked. Second, if some exception handler returns a HttpResponse then the response handlers will be invoked. So your custom process_response may or may not be called after an exception occurs.
Change History (9)
comment:1 Changed 9 years ago by
|Summary:||when process_response and process_exception middleware is invoked → Document when process_response and process_exception middleware is invoked|