fix: avoid MySQL timezone dependency in billing admin

This commit is contained in:
QiuSW
2026-07-04 16:43:57 +08:00
parent fb1037933d
commit 0d6b97f44d
4 changed files with 40 additions and 4 deletions
+14
View File
@@ -1089,3 +1089,17 @@
- 失败用例:`test_signup_creates_unverified_user_wallet_with_zero_points_and_no_ledger`、`test_unverified_email_cannot_establish_login_session`。
- 失败原因:工作区既有 `config/settings.py` 未提交改动将 `ACCOUNT_EMAIL_VERIFICATION` 从 `mandatory` 改为 `none`,导致注册不发验证邮件、未验证用户也能建立登录 session;该文件不属于 T-603,本轮未纳入提交。
- 下一步:恢复 `ACCOUNT_EMAIL_VERIFICATION="mandatory"` 后,重跑上述失败用例和完整测试;全部通过后把 T-603 从 `BLOCKED` 改为 `DONE`。
## 2026-07-04 线上 admin ExchangeRate 500 热修
- 状态:DONE
- 现象:线上访问 `https://cm.833729.com/admin/billing/exchangerate/` 返回 500;未登录 curl 为 302,已登录 admin 页面复现 500。
- 根因:Django admin 的 `date_hierarchy` 会对 DateTime 字段做按日期层级聚合;MySQL 后端在 `USE_TZ=True` 且 `TIME_ZONE=Asia/Shanghai` 时需要 MySQL 时区表支持 `CONVERT_TZ`。生产 MySQL 当前未加载时区表,`ExchangeRateAdmin.date_hierarchy="effective_from"` 渲染时报 `ValueError: Database returned an invalid datetime value. Are time zone definitions for your database installed?`
- 变更:
- `apps/billing/admin.py`:移除 `PointsLedgerAdmin`、`ExchangeRateAdmin`、`RechargeOrderAdmin`、`CallRecordAdmin` 的 DateTime `date_hierarchy`,避免同类页面因 MySQL 时区表缺失 500;保留 `list_filter` 日期筛选。
- `apps/billing/tests.py`:新增 `BillingAdminTests.test_exchange_rate_changelist_renders_when_rates_exist`,覆盖有汇率数据时 admin 列表页必须 200。
- 验证:
- `py -3.12 -m py_compile apps\billing\admin.py apps\billing\tests.py`:通过。
- `py -3.12 manage.py check`:通过,0 issues。
- `py -3.12 manage.py test apps.billing.tests.BillingAdminTests.test_exchange_rate_changelist_renders_when_rates_exist --keepdb --noinput --verbosity 2`:通过,1 test OK;测试阶段仍有既有 allauth MySQL `models.W036` 警告。
- 下一步:提交并部署后,在 VPS 上重启 `cmhub-web.service`,用 Django test client 或浏览器确认 `/admin/billing/exchangerate/` 已恢复 200。