-
Notifications
You must be signed in to change notification settings - Fork 99
bugfix: 修改mysql场景下的时间精度不一致的问题 #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ | |
| from trpc_agent_sdk.storage import DEFAULT_MAX_VARCHAR_LENGTH | ||
| from trpc_agent_sdk.storage import DynamicJSON | ||
| from trpc_agent_sdk.storage import DynamicPickleType | ||
| from trpc_agent_sdk.storage import PreciseNow | ||
| from trpc_agent_sdk.storage import PreciseTimestamp | ||
| from trpc_agent_sdk.storage import SqlCondition | ||
| from trpc_agent_sdk.storage import SqlKey | ||
|
|
@@ -155,8 +156,8 @@ class StorageSession(SessionStorageBase): | |
| nullable=True) | ||
| conversation_count: Mapped[int] = mapped_column(Integer, default=0) | ||
|
|
||
| create_time: Mapped[datetime] = mapped_column(PreciseTimestamp, default=func.now()) | ||
| update_time: Mapped[datetime] = mapped_column(PreciseTimestamp, default=func.now(), onupdate=func.now()) | ||
| create_time: Mapped[datetime] = mapped_column(PreciseTimestamp, default=PreciseNow()) | ||
| update_time: Mapped[datetime] = mapped_column(PreciseTimestamp, default=PreciseNow(), onupdate=PreciseNow()) | ||
|
|
||
|
Comment on lines
+159
to
161
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 本次变更新增 触发条件: 在 MySQL 场景下,对 实际影响: 计划标题“修改 mysql 场景下的时间精度不一致的问题”仅对 修正方向: 将 |
||
| storage_events: Mapped[list[SessionStorageEvent]] = relationship( | ||
| "SessionStorageEvent", | ||
|
|
@@ -731,7 +732,7 @@ async def _get_session(self, sql_session: SqlSession, app_name: str, user_id: st | |
| logger.debug("Session %s is expired", session_id) | ||
| return None | ||
|
|
||
| storage_session.update_time = func.now() | ||
| storage_session.update_time = PreciseNow() | ||
| await self._sql_storage.commit(sql_session) | ||
|
|
||
| return storage_session | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
问题: 新增的
TestPreciseNow仅断言PreciseNow().compile(dialect=...)的独立字符串输出(CURRENT_TIMESTAMP(6)/now()/CURRENT_TIMESTAMP),未验证其在mapped_column(default=, onupdate=)中实际渲染出的 DDL,也未验证作为属性赋值时 UPDATE 语句的 SET 片段。触发条件: SQLAlchemy 升级或
@compiles实现调整后,独立编译输出可能仍正确,但列默认值/onupdate的 DDL 渲染路径发生回归时无测试拦截。实际影响: 本次变更的核心契约——MySQL 下
create_time/update_time列 DDL 为DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)——缺少回归保护,精度回归可能在不被察觉时引入。修正方向: 在
TestPreciseNow中增加用例,对StorageSession.__table__执行CreateTable(...).compile(dialect=mysql.dialect()),断言 DDL 包含DEFAULT CURRENT_TIMESTAMP(6)与ON UPDATE CURRENT_TIMESTAMP(6)。