fix(sessions): list only the empty user's sessions in SqliteSessionService - #7171
Open
yupengtang wants to merge 1 commit into
Open
yupengtang wants to merge 1 commit into
yupengtang wants to merge 1 commit into
Conversation
…rvice list_sessions chose between the per-user and all-users queries with a truthiness check, so user_id='' listed every user's sessions, merged with their user-scoped state. Check for None instead, as RedisSessionService does since 4b26bba, and add a contract test for the empty user id. The Redis note about the same divergence is removed since that backend already passes it.
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.
Link to Issue or Description of Change
2. Or, if no issue exists, describe the change:
Problem:
SqliteSessionService.list_sessionspicks between the per-user query and the all-users query withif user_id:. An empty string is falsy, solist_sessions(app_name=..., user_id='')returns every user's sessions, each merged with that user'suser:state.create_sessionacceptsuser_id='', and the in-memory, database and Redis services all return only that user's sessions.This is the same bug 4b26bba fixed in
RedisSessionService. The note about it intests/unittests/sessions/_conformance.pyis still there, although Redis now passes.Solution:
Check
user_id is not Nonein both places inlist_sessions, matching the Redis fix. Add a contract test that runs on every registered backend, and remove the stale Redis note since there is now a test for it.PerAgentDatabaseSessionServicewraps the SQLite service, so it is fixed too.FirestoreSessionService.list_sessionshas the same check, but Firestore rejects empty document ids, so a session withuser_id=''can't exist there. I left it alone.Testing Plan
Unit Tests:
test_list_sessions_with_empty_user_id_lists_only_that_userpasses on all six backends in_conformance.BACKENDS. With thesqlite_session_service.pychange reverted, it fails forsqliteandper_agent_databaseonly.Manual End-to-End (E2E) Tests:
Before:
After:
Checklist