Opened 7 weeks ago

Closed 7 weeks ago

Last modified 7 weeks ago

#36506 closed Bug (wontfix)

sessions.backend.cache.SessionStore.clear_expired doesn't clean

Reported by: Efe Öge Owned by: Efe Öge
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 (last modified by Efe Öge)

Hello,

We've been using Redis as cache backend for session storage. 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.

Change History (5)

comment:1 by Efe Öge, 7 weeks ago

Type: UncategorizedBug

comment:2 by Efe Öge, 7 weeks ago

Owner: set to Efe Öge
Status: newassigned

comment:3 by Efe Öge, 7 weeks ago

Description: modified (diff)

comment:4 by Sarah Boyce, 7 weeks ago

Resolution: wontfix
Status: assignedclosed

I think future work here is likely captured by #19201

Note that it has been this way since the beginning 5fec97b9df6ea075483276de159e522a29437773 but I can see no tests were added to CacheSessionTests.
I feel like updating this to a NotImplementedError would be a breaking change and that's probably why it was designed this way.

comment:5 by Efe Öge, 7 weeks ago

Thanks Sarah for your message.

I posted on the #19201 that I would like to on that. https://code.djangoproject.com/timeline?from=2025-07-20T10%3A17%3A56-05%3A00&precision=second

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