Skip to content

Commit 585141e

Browse files
xuanyang15copybara-github
authored andcommitted
fix: Use PreciseTimestamp for create and update time in database session service to improve precision
PiperOrigin-RevId: 794422113
1 parent 114db93 commit 585141e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/google/adk/sessions/database_session_service.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from typing import Optional
2323
import uuid
2424

25-
from google.genai import types
2625
from sqlalchemy import Boolean
2726
from sqlalchemy import delete
2827
from sqlalchemy import Dialect
@@ -132,9 +131,11 @@ class StorageSession(Base):
132131
MutableDict.as_mutable(DynamicJSON), default={}
133132
)
134133

135-
create_time: Mapped[DateTime] = mapped_column(DateTime(), default=func.now())
136-
update_time: Mapped[DateTime] = mapped_column(
137-
DateTime(), default=func.now(), onupdate=func.now()
134+
create_time: Mapped[datetime] = mapped_column(
135+
PreciseTimestamp, default=func.now()
136+
)
137+
update_time: Mapped[datetime] = mapped_column(
138+
PreciseTimestamp, default=func.now(), onupdate=func.now()
138139
)
139140

140141
storage_events: Mapped[list[StorageEvent]] = relationship(
@@ -313,8 +314,8 @@ class StorageAppState(Base):
313314
state: Mapped[MutableDict[str, Any]] = mapped_column(
314315
MutableDict.as_mutable(DynamicJSON), default={}
315316
)
316-
update_time: Mapped[DateTime] = mapped_column(
317-
DateTime(), default=func.now(), onupdate=func.now()
317+
update_time: Mapped[datetime] = mapped_column(
318+
PreciseTimestamp, default=func.now(), onupdate=func.now()
318319
)
319320

320321

@@ -332,8 +333,8 @@ class StorageUserState(Base):
332333
state: Mapped[MutableDict[str, Any]] = mapped_column(
333334
MutableDict.as_mutable(DynamicJSON), default={}
334335
)
335-
update_time: Mapped[DateTime] = mapped_column(
336-
DateTime(), default=func.now(), onupdate=func.now()
336+
update_time: Mapped[datetime] = mapped_column(
337+
PreciseTimestamp, default=func.now(), onupdate=func.now()
337338
)
338339

339340

0 commit comments

Comments
 (0)