Opened 8 weeks ago
Last modified 7 weeks ago
#36506 closed Bug
sessions.backend.cache.SessionStore.clear_expired doesn't clean — at Initial Version
Reported by: | Efe Öge | Owned by: | |
---|---|---|---|
Component: | contrib.sessions | Version: | 5.2 |
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
Hello,
We've been using Redis as the session storage for our cache backend. To clean up old sessions, we run the "python manage.py clearsessions" management command. This command internally calls the clear_expired method on the associated SessionStore. If clear_expired raises a NotImplementedError, the command catches it and raises a CommandError, indicating that the session backend doesn't support session cleanup. This behavior makes sense. https://github.com/django/django/blob/main/django/contrib/sessions/management/commands/clearsessions.py
However, in the case of the cache backend, the clear_expired method is currently just an empty function. https://github.com/django/django/blob/main/django/contrib/sessions/backends/cache.py#L140
I would therefore recommend either explicitly raising a NotImplementedError here, or implementing a (potentially slow) cleanup mechanism that actually removes expired sessions.
What are your thoughts on this? If this looks like a bug to you, I’d be happy to help by sending a patch.