Skip to content

fix: treat an empty session id as absent in DatabaseSessionService - #7899

Open
lisry-1 wants to merge 1 commit into
google:mainfrom
lisry-1:fix/database-empty-session-id-clean
Open

lisry-1 wants to merge 1 commit into
google:mainfrom
lisry-1:fix/database-empty-session-id-clean

Conversation

@lisry-1

@lisry-1 lisry-1 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Summary

DatabaseSessionService.create_session computed has_user_provided_id from session_id is not None, so an empty string was accepted as a user-provided id and stored verbatim. A session stored under id '' is unaddressable through the HTTP API and collides with every other empty-id creation for the same (app, user) pair (the second creation raises AlreadyExistsError). Every other backend (in-memory, sqlite, redis, mongodb, firestore) treats an empty id as absent and generates one.

Changes

  • Derive has_user_provided_id from the truthiness of session_id and generate a uuid when it is falsy, matching the other backends.

Tests

Adds a conformance test test_create_session_with_empty_id_generates_one (parameterized across the registered backends) asserting that an empty id yields a non-empty generated id.

create_session computed has_user_provided_id from 'session_id is not
None', so an empty string was accepted as a user-provided id and stored
verbatim. A session stored under id '' is unaddressable through the HTTP
API and collides with every other empty-id creation for the same
(app, user) pair. Every other backend (in-memory, sqlite, redis, mongodb,
firestore) treats an empty id as absent and generates one.

Derive has_user_provided_id from the truthiness of session_id and generate
a uuid when it is falsy, matching the other backends. Adds a conformance
test that an empty id yields a non-empty generated id across backends.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ Proxy