Repository navigation
fix: store sessions in the database and limit them to 24 hours - #1128
Merged
Merged
Conversation
nimish-ks
approved these changes
Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔍 Overview
Moves sessions to Django's database-backed session store and shortens the default session lifetime to 24 hours. Session data is kept server-side and the browser cookie only carries a session key. Signing out removes the session record.
💡 Proposed Changes
SESSION_ENGINEis nowdjango.contrib.sessions.backends.db. Thedjango_sessiontable already exists, so there is no migration.SESSION_LIFETIME_HOURSenvironment variable sets a different whole number of hours. Any other value stops the application from starting, with a clear error. It is documented in.env.example.clearsessions). It is registered on migrate and at worker startup, like the existing sweeps, and runs on the maintenance worker. No new queue or process.🖼️ Screenshots or Demo
N/A — no UI change.
📝 Release Notes
Sessions are now stored server-side and end 24 hours after sign-in by default. Self-hosted instances can change this with
SESSION_LIFETIME_HOURS. Everyone will need to sign in again once after upgrading.❓ Open Questions
N/A
🧪 Testing
SESSION_LIFETIME_HOURS=6. With a simulated clock, a session write at hour 20 and a password change at hour 23 leave the end at hour 24, and the session is not accepted at hour 25. Ordinary requests do not rewrite the session. The purge job removed an expired session on the real worker. A browser that still holds an old cookie is sent to the login page.🎯 Reviewer Focus
SESSION_ENGINEandsession_lifetime_secondsinbackend/backend/settings.py,start_session_lifetimeinbackend/api/signals.py,relogin_preserving_sessioninbackend/api/utils/reauth.py, andbackend/api/tasks/sessions.py.➕ Additional Context
django_sessionper session-authenticated request. API tokens (CLI, SDKs) do not use sessions and are unaffected.SESSION_LIFETIME_HOURS: docs: document SESSION_LIFETIME_HOURS docs#277.✨ How to Test the Changes Locally
docker compose -f dev-docker-compose.yml exec backend pytest \ tests/test_session_logout.py \ tests/test_session_lifetime.py \ tests/tasks/test_sessions.py \ tests/api/test_rqworker_command.pyThen sign in to the console, sign out, and sign in again.
💚 Did You...