Repository navigation
Description
🔴 Required Information
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
DatabaseSessionServicewith a PostgreSQL database usingasyncpgdriver - 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.
Observed Behavior:
sqlalchemy.dialects.postgresql.asyncpg.Error: <class 'asyncpg.exceptions.DataError'>:
invalid input for query argument $5: datetime.datetime(2026, 2, 3, 21, 32, 50, 353909,
tzinfo=datetime.timezone.utc) (can't subtract offset-naive and offset-aware datetimes)
During the INSERT:
INSERT INTO sessions (app_name, user_id, id, state, create_time, update_time)
VALUES ($1, $2, $3, $4, $5, $6)Environment Details:
- ADK Library Version: 1.22.1+
- Desktop OS: macOS (also affects Linux)
- Python Version: 3.13
Model Information:
- 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:
now = datetime.now(timezone.utc)
is_sqlite = self.db_engine.dialect.name == "sqlite"
if is_sqlite:
now = now.replace(tzinfo=None)But PostgreSQL was not handled, even though its default TIMESTAMP type is also WITHOUT TIME ZONE.
Logs:
sqlalchemy.dialects.postgresql.asyncpg.Error: <class 'asyncpg.exceptions.DataError'>:
invalid input for query argument $5: datetime.datetime(2026, 2, 3, 21, 32, 50, 353909,
tzinfo=datetime.timezone.utc) (can't subtract offset-naive and offset-aware datetimes)
Minimal Reproduction Code:
from google.adk.sessions import DatabaseSessionService
# Configure with PostgreSQL + asyncpg
session_service = DatabaseSessionService(
db_url="postgresql+asyncpg://user:pass@localhost:5432/agent_sessions"
)
# This will fail when creating any sessionHow often has this issue occurred?:
- Always (100%) - when using PostgreSQL with asyncpg
Fix:
PR #4365 addresses this by also stripping the timezone for PostgreSQL:
is_postgres = self.db_engine.dialect.name == "postgresql"
if is_sqlite or is_postgres:
now = now.replace(tzinfo=None)
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…