Opened 7 years ago
Closed 6 years ago
#28763 closed New feature (fixed)
Allow SessionStore's to be easily overridden to make dynamic the session cookie age
Reported by: | Jaime Herencia Enjuto | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | contrib.sessions | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If I want to make dynamic my SESSION_COOKIE_AGE setting based on certain parameters of the session I need to reimplement in my SessionStore subclasses the following methods:
- get_expiry_age
- get_expiry_date
just to override the points where settings.SESSION_COOKIE_AGE is used.
Change History (9)
comment:2 by , 7 years ago
Summary: | Allow SessionStore's to easily override or make dynamic the session cookie age → Allow SessionStore's to be easily overridden to make dynamic the session cookie age |
---|
comment:3 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
That seems useful.
comment:4 by , 7 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
Triage Stage: | Accepted → Unreviewed |
Actually, it looks like you can call SessionStore.set_expiry
? One place to do so would be in a middleware that's listed below the session middleware, when processing a response.
class SessionExpiryPolicyMiddleware(object): def __init__(self, get_response): self.get_response = get_response def __call__(self, request): response = self.get_response(request) if response.session.modified and response.status_code != 500: response.session.set_expiry(response.session.calculate_expiry()) return response
comment:5 by , 7 years ago
You are right that could be a way to achieve this, I know there are other ways to do this but don't you think that the responsible of calculating Session expirations should be the SessionStore not a middleware?
comment:6 by , 7 years ago
I think it would be worth discussing in the django-developers mailing list.
comment:7 by , 7 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
A test should be added so the change isn't inadvertently refactored away.
I've created a pull request: https://github.com/django/django/pull/9314