fix(sessions): correct timezone handling for PostgreSQL in DatabaseSessionService#5355
fix(sessions): correct timezone handling for PostgreSQL in DatabaseSessionService#5355zouyi100 wants to merge 5 commits 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. |
|
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
|
Hi @zouyi100 , Thank you for your contribution! We appreciate you taking the time to submit this pull request. |
2f41364 to
cb19676
Compare
|
Hi @rohityan |
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.#5354