[Bug] v4.28.1 Dashboard 统计服务因时区信息缺失导致查询失败
问题描述
从 v4.28.0 开始,访问 WebUI 的“数据与日志”页面时,页面顶部提示 “统计数据加载失败,请稍后重试”。
如何复现?
启动 AstrBot v4.28.0 或 v4.28.1。 打开 WebUI,进入「数据与日志」页面。 页面提示“统计数据加载失败”,日志中立即出现上述 StatementError。
AstrBot 版本
4.28.0/4.28.1
操作系统
Windows
部署方式
AstrBot Launcher
使用的消息平台适配器
aiocqhttp(OneBot v11)
错误日志
[ERRO] [v4.28.1] [services.stat_service:295]:
ValueError: Datetime values must have timezone information.
Use datetime.now(timezone.utc), or annotate the field with NaiveDatetime for naive storage.
sqlalchemy.exc.StatementError: (builtins.ValueError) Datetime values must have timezone information.
[SQL: SELECT platform_stats.id, platform_stats.timestamp, platform_stats.platform_id, platform_stats.platform_type, platform_stats.count
FROM platform_stats
WHERE platform_stats.timestamp >= ? ORDER BY platform_stats.timestamp]
[parameters: [{}]]
辅助信息
检查清单
The cause is on the dependency side: SQLModel 0.0.45 changed datetime fields that don't declare a column type to UTCDateTime, which refuses naive datetimes. That is the sqlmodel/sql/sqltypes.py process_bind_param frame in your log, and the stats query binds a naive datetime.now(). #10211, merged into master today, declares DateTime(timezone=False) on the existing datetime columns, so this is fixed there. Until the next release, installing sqlmodel<0.0.45 in the launcher's venv should avoid it.
结论:本体 bug;master 已由 #10211 修复,尚未发版
根因:查询用 naive 的 datetime.now() 与 platform_stats.timestamp 比较,而 SQLModel ≥0.0.45 把未声明类型的 datetime 列推断为 UTCDateTime,绑定 naive 值即抛 ValueError(最小复现,未跑完整实例)—— astrbot/core/db/sqlite.py:277 @ v4.28.1,同类 :854、:1916、:1974
建议:升级到含 #10211 的版本(该 PR 显式声明 DateTime(timezone=False));或先将 sqlmodel 固定为 <0.0.45
建议标签:area:core priority: p2
🤖 本评论由 AI 生成,结论已基于仓库代码核实;如有出入,以维护者判断为准。
这个什么时候publish到release?同样的问题出现了,有点影响
fixed in #10211