fix(sessions): correct timezone handling for PostgreSQL in DatabaseSessionService#5355
Open
zouyi100 wants to merge 1 commit intogoogle:mainfrom
Open
fix(sessions): correct timezone handling for PostgreSQL in DatabaseSessionService#5355zouyi100 wants to merge 1 commit intogoogle:mainfrom
zouyi100 wants to merge 1 commit intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Collaborator
|
Response from ADK Triaging Agent Hello @zouyi100, thank you for your contribution! To move forward with this PR, please address the following points from our contribution guidelines:
You can find more details in our contribution workflow guidelines. Thanks! |
…ssionService `create_session` already stored UTC naive datetimes for both SQLite and PostgreSQL, but the corresponding read path (`get_update_timestamp`) and write path in `append_event` only handled SQLite, causing incorrect POSIX timestamps and potential false stale-session errors on non-UTC hosts. - `get_update_timestamp` / `update_timestamp_tz`: treat PostgreSQL the same as SQLite — attach UTC tzinfo before calling `.timestamp()`. - `to_session`: thread the new `is_postgresql` flag through to `get_update_timestamp`. - `append_event`: use UTC naive datetime for PostgreSQL `update_time` (consistent with `create_session`); use UTC-aware datetime for all other non-SQLite dialects instead of local-time naive. - `get_session` / `list_sessions`: propagate `is_postgresql` to `to_session`.
02fe61c to
0e57908
Compare
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.
Problem:
create_sessionalready stored UTC naive datetimes for both SQLite andPostgreSQL, but the corresponding read path (
get_update_timestamp) andwrite path in
append_eventonly handled SQLite. On non-UTC hosts thiscauses
session.last_update_timeto be off by the local timezone offsetafter
create_session, and potentially triggers false stale-session errorsafter the first
append_eventcall on PostgreSQL.Three specific inconsistencies:
get_update_timestamponly added UTC tzinfo for SQLite, not PostgreSQL.append_eventwrote local-time naiveupdate_timefor PostgreSQL, whilecreate_sessionwrote UTC naive.get_session/list_sessionsdid not propagateis_postgresqltoto_session.Solution:
Extend the existing SQLite UTC-naive convention to PostgreSQL consistently
across all read and write paths.
Testing Plan
Unit Tests:
pytest tests/unittests/sessions/ --deselect
"tests/unittests/sessions/test_session_service.py::test_get_session_with_config[SessionServiceType.DATABASE]"
169 passed (the deselected test is a pre-existing Windows-only OSError
unrelated to this change)
Manual End-to-End (E2E) Tests:
Tested with SQLite (
:memory:) and verifiedsession.last_update_timereturns correct UTC-based POSIX timestamps after
create_sessionandappend_event.