Code

Opened 6 years ago

Closed 5 years ago

Last modified 3 years ago

#8538 closed (fixed)

Document when process_response and process_exception middleware is invoked

Reported by: TP Owned by: jacob
Component: Documentation Version: master
Severity: Keywords: middleware
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

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.

Attachments (1)

middleware_warnings.patch (1.3 KB) - added by deadwisdom 5 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from when process_response and process_exception middleware is invoked to Document when process_response and process_exception middleware is invoked

comment:2 Changed 5 years ago by jacob

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Accepted

There's a graphic in ch 3 of the django book that explains this; we should adapt it into the middleware docs for clarity.

comment:3 Changed 5 years ago by programmerq

I'm willing to write a patch for this. Is it appropriate to take the graphic from the Django book verbatim and include it here?

Changed 5 years ago by deadwisdom

comment:4 Changed 5 years ago by deadwisdom

  • Has patch set
  • Owner changed from nobody to deadwisdom

comment:5 Changed 5 years ago by deadwisdom

  • Owner changed from deadwisdom to nobody

Ah, sorry hadn't updated and just did this. Go ahead programmerq, if you want to take from the book.

comment:6 Changed 5 years ago by jacob

  • Owner changed from nobody to jacob
  • Status changed from new to assigned

comment:7 Changed 5 years ago by jacob

  • Resolution set to fixed
  • Status changed from assigned to closed

This has been fixed for a bit; not exactly sure when it got checked in.

comment:8 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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.