Skip to content

DatabaseSessionService.get_session() raises TypeError: fromisoformat: argument must be str #6352

Description

@amitjborate

Version: google-adk==2.3.0
Python: 3.12

Description:
DatabaseSessionService.get_session() raises TypeError: fromisoformat: argument must be str
on SQLite databases when reading back session or event rows.

Root cause:
PreciseTimestamp (in src/google/adk/sessions/schemas/shared.py) is a TypeDecorator
backed by SQLAlchemy DateTime. It does not define process_result_value. For SQLite,
DateTime columns are created with REAL affinity and written as Unix epoch floats
(e.g. StorageEvent.from_event calls datetime.fromtimestamp(event.timestamp) which
SQLite stores as REAL). On read, SQLAlchemy's C-extension str_to_datetime is invoked
and raises TypeError: fromisoformat: argument must be str because it receives a float.

Reproduce:

  1. Run any agent using DatabaseSessionService with a SQLite URI.
  2. In a second process, open the same DB and call get_session().

Expected: session and events returned correctly.
Actual: TypeError: fromisoformat: argument must be str

File "../sqlalchemy/cyextension/resultproxy.pyx", line 79, in _apply_processors
File "../sqlalchemy/cyextension/processors.pyx", line 40, in str_to_datetime

Fix:
Add process_result_value to PreciseTimestamp to handle the float→datetime conversion:

def process_result_value(self, value, dialect):
    if value is None:
        return None
    if isinstance(value, (int, float)):
        from datetime import datetime
        return datetime.fromtimestamp(value)
    return value  # already a datetime (or str handled by base impl)

Metadata

Metadata

Labels

request clarification[Status] The maintainer need clarification or more information from the authorservices[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions