You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DatabaseSessionService fails with PostgreSQL + asyncpg: can't subtract offset-naive and offset-aware datetimes #4366
Describe the Bug:
When using DatabaseSessionService with PostgreSQL and asyncpg, creating a new session fails with a DataError because timezone-aware Python datetime objects are being passed to PostgreSQL TIMESTAMP WITHOUT TIME ZONE columns.
Steps to Reproduce:
Configure DatabaseSessionService with a PostgreSQL database using asyncpg driver
Set SESSION_SERVICE_URI=postgresql+asyncpg://user:pass@localhost:5432/db
Create a new session via the ADK agent
Error occurs on session creation
Expected Behavior:
Session should be created successfully in the PostgreSQL database.
Are you using LiteLLM: N/A (issue is in session service, not model)
Which model is being used: N/A
🟡 Optional Information
Regression:
Yes. This worked prior to commit 1063fa5 which changed from database-generated timestamps (func.now()) to explicit Python datetimes (datetime.now(timezone.utc)).
The SQLite case was correctly handled by stripping the timezone:
fromgoogle.adk.sessionsimportDatabaseSessionService# Configure with PostgreSQL + asyncpgsession_service=DatabaseSessionService(
db_url="postgresql+asyncpg://user:pass@localhost:5432/agent_sessions"
)
# This will fail when creating any session
How often has this issue occurred?:
Always (100%) - when using PostgreSQL with asyncpg
Fix:
PR #4365 addresses this by also stripping the timezone for PostgreSQL:
Here is a minimal monkey patch that fixes it. Just add this at the top of an early imported file (before you use any adk stuff):
Patch: use a datetime subclass so we don't touch immutable built-in
from datetime import datetime as _RealDateTime, timezone
import google.adk.sessions.database_session_service as _db_session_mod
class _NaiveUTCDateTime(_RealDateTime): @classmethod
def now(cls, tz=None):
r = _RealDateTime.now(tz or timezone.utc)
return r.replace(tzinfo=None) if r.tzinfo else r
Activity
marcopellegrino-devoteam commentedon Feb 6, 2026
Found the same issue.
Only from ADK 1.24.0
It works with 1.23.0
mariokorte commentedon Feb 6, 2026
+1 here for 1.24.
I’ve added a monkey_patch in my project with the content of #4365 and this works for now.
aidanandrews22 commentedon Feb 7, 2026
+1
Here is a minimal monkey patch that fixes it. Just add this at the top of an early imported file (before you use any adk stuff):
Patch: use a datetime subclass so we don't touch immutable built-in
from datetime import datetime as _RealDateTime, timezone
import google.adk.sessions.database_session_service as _db_session_mod
class _NaiveUTCDateTime(_RealDateTime):
@classmethod
def now(cls, tz=None):
r = _RealDateTime.now(tz or timezone.utc)
return r.replace(tzinfo=None) if r.tzinfo else r
_db_session_mod.datetime = _NaiveUTCDateTime
karticksaxena commentedon Feb 8, 2026
Facing the same issue, for now reverted to the previous version 1.23.0
fix: consistent UTC timestamp handling for PostgreSQL in DatabaseSess…
fix: consistent UTC timestamp handling for PostgreSQL in DatabaseSess…
wuliang229 commentedon Feb 10, 2026
@mariokorte @filipecaixeta @The-Batman-Code @aidanandrews22 should be fixed by 19b6076
fix: consistent UTC timestamp handling for PostgreSQL in DatabaseSess…
fix: consistent UTC timestamp handling for PostgreSQL in DatabaseSess…