Repository navigation
DatabaseSessionService on PostgreSQL changes state values and can't store a NUL #7854
Description
Describe the Bug:
Currently, DynamicJSON stores state and events as JSONB on PostgreSQL, so dict keys come back reordered, floats from 1e16 up come back as ints, -0.0 as 0.0, and text with a NUL is refused. The same service on SQLite stores json.dumps text and keeps every value.
Steps to Reproduce:
With google-adk[db] and psycopg[binary] installed, run this as python repro.py postgresql+psycopg://localhost/postgres and as python repro.py sqlite+aiosqlite:///a.db:
import asyncio, sys
from google.adk.events import Event, EventActions
from google.adk.sessions import DatabaseSessionService
from google.genai import types
async def main():
svc = DatabaseSessionService(sys.argv[1])
s = await svc.create_session(app_name="a", user_id="u")
d = {"k": {"b": 1, "a": 2}, "x": 1e23, "z": -0.0}
await svc.append_event(s, Event(author="a", actions=EventActions(state_delta=d)))
s = await svc.get_session(app_name="a", user_id="u", session_id=s.id)
print(s.state["k"], s.state["x"], s.state["z"])
# PostgreSQL: {'a': 2, 'b': 1} 100000000000000000000000 0.0
# SQLite: {'b': 1, 'a': 2} 1e+23 -0.0
# the float 1e23 is 99999999999999991611392, so the int is a different number
t = types.Content(role="model", parts=[types.Part(text="a\x00b")])
await svc.append_event(s, Event(author="a", content=t))
# PostgreSQL: sqlalchemy.exc.DataError: (psycopg.errors.UntranslatableCharacter) unsupported Unicode escape sequence
# SQLite: no error
asyncio.run(main())Expected Behavior:
On PostgreSQL the script prints the SQLite line and appends the event.
Observed Behavior:
The state comes back as the PostgreSQL: line shows, and the last append_event raises sqlalchemy.exc.DataError: (psycopg.errors.UntranslatableCharacter) unsupported Unicode escape sequence with DETAIL: \u0000 cannot be converted to text.
Environment Details:
- ADK Library Version (pip show google-adk): 2.13.0 and main
- Desktop OS: macOS 26.7.1, arm64 (Darwin 25.6.0)
- Python Version (python -V): Python 3.12.16
- PostgreSQL 18.6, SQLAlchemy 2.1.6, psycopg 3.3.6; asyncpg 0.32.0 gives the same state and the same NUL error
Model Information:
- Are you using LiteLLM: No
- Which model is being used: N/A
Additional Context:
Through a json column instead of jsonb, PostgreSQL returns the state dict and the NUL text unchanged.
How often has this issue occurred?:
- Always (100%)
Activity