修复广告收益用户详情加载失败 #180
Reference in New Issue
Block a user
Delete Branch "codex/ad-revenue-user-drawer-fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
问题原因
修复内容
验证结果
🤖 review-pr 深审结论
🟢 通过 — 两个独立修复,均正确、对症、有测试覆盖,风险低。
① 金币明细混合时区排序崩溃(
app/admin/repositories/queries.py)根因准确:线上 PostgreSQL 广告记录
created_at为 aware UTC,签到记录经_cn_wall_to_utc转成 naive UTC,混排触发can't compare offset-naive and offset-aware。修复用_coin_record_sort_key→_as_utc统一成 aware UTC 再排序;因各来源入 rows 时都已是 UTC,_as_utc把 naive 当 UTC → 绝对时刻正确 → 排序正确。② 用户存在性检查避免展开完整 user 表(
routers/users.py+repositories/user.py)原
get_user_by_id(db.get(User)加载完整行)在旧库缺 ORM 新列时查询失败;改为user_exists(select(User.id)只查主键),语义等价(存在→继续 / 不存在→404),不再依赖完整表结构。测试:混排排序用例 + 「存在性检查不展开完整 user 表」断言,覆盖到位。
小提醒(非阻断):
_as_utc(created_at)假设created_at非空;若某来源返回 null 会AttributeError。实际这些表应为 NOT NULL、非本 PR 引入,留意即可。review-pr 自动深审 · 完整仓 worktree 上下文