Opened 5 years ago
Closed 5 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 , 5 years ago
Type: | Uncategorized → New feature |
---|
comment:2 by , 5 years ago
Component: | Uncategorized → contrib.sessions |
---|---|
Type: | New feature → Uncategorized |
comment:3 by , 5 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Type: | Uncategorized → New 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.