Opened 5 years ago

Closed 5 years ago

#19648 closed Bug (duplicate)

Middleware process_exception not called when another middleware raises an error

Reported by: Anssi Kääriäinen Owned by: nobody
Component: Core (Other) Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


It seems that process_exception isn't called at all if anther middleware below it raises an exception in process_request. This has some interesting side-effects. For example, if you have this setting:


The end result is that first, transaction middleware will open a transaction, second SavesToDB will save to DB, finally RaisesException raises an exception. Now, process_exception isn't called, we go directly to process_response stage. assume that RaisesException and SavesToDB do nothing. So, finally transaction middleware commits the transaction. Which seems like exactly the wrong thing to do. My interpretation is that if an exception happens below transaction middleware, then the transaction will be rolled back, no matter if the source is the view or another middleware.

IMO we should do a process_exception() dance in case another middleware raises an exception. Probably we should go just through those middleware classes before the exception.

Another option is do immediate 500 response and not proceed to do anything else if process_request raises an exception. Middleware's process_request should not throw an error, so this would be "critical error, bail out immediately" response to erroneous middleware.

Change History (2)

comment:1 Changed 5 years ago by Michael Manfre

Related to (possibly a dupe of) #12250, which is the lack of process_exception() dance when the exception is raised from process_view.

comment:2 Changed 5 years ago by Anssi Kääriäinen

Resolution: duplicate
Status: newclosed

I made a comment of this issue in #12250. I will close this one as duplicate of #12250.

Note: See TracTickets for help on using tickets.
Back to Top