From 0ade58a750aef7bf4496fb456783578a5a8a66ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Thu, 3 Sep 2026 16:39:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(summary):=20=E7=A9=BA=E8=A1=A8=E5=AE=88?= =?UTF-8?q?=E5=8D=AB=E5=AE=B9=E9=94=99=E2=80=94=E2=80=94=E8=A1=A8=E6=9C=AA?= =?UTF-8?q?=E5=BB=BA(=E6=BC=8F=E8=BF=81=E7=A7=BB=E7=9A=84=E5=8D=87?= =?UTF-8?q?=E7=BA=A7)=E4=B9=9F=E5=9B=9E=E9=80=80=E6=97=A7=E8=81=9A?= =?UTF-8?q?=E5=90=88,=E4=B8=8D=20500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Code --- yunke-server/app/storage/summary.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/yunke-server/app/storage/summary.py b/yunke-server/app/storage/summary.py index 6209f02..a0b4f05 100644 --- a/yunke-server/app/storage/summary.py +++ b/yunke-server/app/storage/summary.py @@ -33,14 +33,20 @@ _SH = ZoneInfo("Asia/Shanghai") async def has_rows(session: AsyncSession) -> bool: - """汇总表是否已有数据(读端点的空表守卫:部署回填前自动回退旧实时聚合)。""" - return bool( - ( - await session.execute( - sa.select(sa.func.count()).select_from(MsgDailyStats) - ) - ).scalar_one() - ) + """汇总表是否已有数据(读端点的空表守卫:部署回填前自动回退旧实时聚合)。 + + 表还不存在(漏跑迁移的升级)与空表同视——回退旧路径,不 500。 + """ + try: + return bool( + ( + await session.execute( + sa.select(sa.func.count()).select_from(MsgDailyStats) + ) + ).scalar_one() + ) + except (sa.exc.OperationalError, sa.exc.ProgrammingError): + return False def day_key(ts_ms: int) -> int: