Skip to content

Commit 0022eb3

Browse files
committed
fix: Strip timezone for PostgreSQL timestamps in DatabaseSessionService
PostgreSQL's default TIMESTAMP type is WITHOUT TIME ZONE, which cannot accept timezone-aware datetime objects from Python. This causes a DataError when using asyncpg: "can't subtract offset-naive and offset-aware datetimes". The existing code already handled this for SQLite by stripping the timezone, but PostgreSQL was not handled. This fix applies the same treatment to PostgreSQL. Fixes the regression introduced in commit 1063fa5 which changed from database-generated timestamps (func.now()) to explicit Python datetimes.
1 parent 524dc29 commit 0022eb3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/google/adk/sessions/database_session_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ async def create_session(
297297
# Store the session
298298
now = datetime.now(timezone.utc)
299299
is_sqlite = self.db_engine.dialect.name == "sqlite"
300-
if is_sqlite:
300+
is_postgres = self.db_engine.dialect.name == "postgresql"
301+
if is_sqlite or is_postgres:
301302
now = now.replace(tzinfo=None)
302303

303304
storage_session = schema.StorageSession(

0 commit comments

Comments
 (0)