Code

#19648 closed Bug (duplicate)

Middleware process_exception not called when another middleware raises an error

Reported by: akaariai 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

Description

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:

MIDDLEWARE_CLASSES = [
    'TransactionMiddleware',
    'SavesToDB',
    'RaisesException'
]

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.

Attachments (0)

Change History (2)

comment:1 Changed 15 months ago by 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 15 months ago by akaariai

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

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

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.