Opened 4 years ago

Closed 4 years ago

#31229 closed New feature (wontfix)

Add setting to allow flexible session saving based on response codes

Reported by: Vincent Wang Owned by: nobody
Component: contrib.sessions Version: 3.0
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

Inside django.contrib.sessions.middleware.SessionMiddleware.process_response (https://github.com/django/django/blob/master/django/contrib/sessions/middleware.py), we have a line where we don't save the session of the request if the response status code is 500. The comment in the code refers to this issue: https://code.djangoproject.com/ticket/3881 where it's concluded that a 500 code is most likely to indicate that it's an incomplete request and the response shouldn't save anything else.

I would find it useful to be able to prevent saving of the session when the response status code is anything in the 5xx status code range. This would be possible if we implemented some setting that defaulted to include the status code 500, but allowed users to override it with a list of status codes where the session would not save.

Change History (3)

comment:1 by Vincent Wang, 4 years ago

Type: UncategorizedNew feature

comment:2 by Vincent Wang, 4 years ago

Component: Uncategorizedcontrib.sessions
Type: New featureUncategorized

comment:3 by Carlton Gibson, 4 years ago

Resolution: wontfix
Status: newclosed
Type: UncategorizedNew feature

Hi Vincent.

I think I'd have to point you to a subclass here. I appreciate that the 500 in question is not easily overridden, but Django itself doesn't return other codes in the 5xx range and I think this is too niche a use-case to merit the API surface area.

We could feasibly add a check method to SessionMiddleware that would facilitate subclassing, but I doubt there's even demand for that.
If you like you can write to the DevelopersMailingList to see if there is support.

Thanks.

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