Skip to content

Conversation

@SXP-Simon
Copy link
Contributor

@SXP-Simon SXP-Simon commented Jan 28, 2026

Modifications / 改动点

updated_at 字段原先在 sa_column_kwargs["onupdate"] 中直接使用了 datetime.now(),导致时间戳仅在模块导入时被计算一次,之后不再变化,结果所有记录的更新时间都被设成了程序启动时间。

本次修改将时间戳生成逻辑封装进 lambda 表达式,使 SQLAlchemy 在每次更新记录时才惰性求值,从而保证时间戳实时更新。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

8fd453455534891e0b034703f5d698a6 3219ed3a90f1273869b3945855e1fdcf af4106b52a2cdc9679081e7574680d90 ---

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

错误修复:

  • 修复多个 SQLModel 实体中的 updated_at 字段,使其时间戳在更新时评估,而不是仅在导入时评估一次。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Fix updated_at fields across multiple SQLModel entities so their timestamps are evaluated at update time instead of only once at import.

updated_at 字段原先在 sa_column_kwargs["onupdate"] 中直接使用了 datetime.now(),导致时间戳仅在模块导入时被计算一次,之后不再变化,结果所有记录的更新时间都被设成了程序启动时间。

本次修改将时间戳生成逻辑封装进 lambda 表达式,使 SQLAlchemy 在每次更新记录时才惰性求值,从而保证时间戳实时更新。
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jan 28, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出一些总体反馈:

  • 由于 created_at/updated_at 在多个模型中有完全相同的定义,可以考虑把它们提取成一个可复用的 mixin 或辅助函数,以避免重复并保持时间戳行为一致。
  • 如果你希望以数据库时间作为唯一可信来源,可以考虑使用 func.now()(或等效的服务端默认值/onupdate)来代替 datetime.now(timezone.utc),这样更新时间就由数据库而不是应用自身的时钟来驱动。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- Since `created_at`/`updated_at` share identical definitions across multiple models, consider extracting them into a reusable mixin or helper function to avoid duplication and keep timestamp behavior consistent.
- If you want the database time to be the single source of truth, you might consider using `func.now()` (or an equivalent server-side default/onupdate) instead of `datetime.now(timezone.utc)` so updates are driven by the DB rather than application clock.

Sourcery 对开源项目是免费的——如果你觉得我们的代码评审有帮助,欢迎帮忙分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进后续评审。
Original comment in English

Hey - I've left some high level feedback:

  • Since created_at/updated_at share identical definitions across multiple models, consider extracting them into a reusable mixin or helper function to avoid duplication and keep timestamp behavior consistent.
  • If you want the database time to be the single source of truth, you might consider using func.now() (or an equivalent server-side default/onupdate) instead of datetime.now(timezone.utc) so updates are driven by the DB rather than application clock.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since `created_at`/`updated_at` share identical definitions across multiple models, consider extracting them into a reusable mixin or helper function to avoid duplication and keep timestamp behavior consistent.
- If you want the database time to be the single source of truth, you might consider using `func.now()` (or an equivalent server-side default/onupdate) instead of `datetime.now(timezone.utc)` so updates are driven by the DB rather than application clock.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:core The bug / feature is about astrbot's core, backend label Jan 28, 2026
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant