From e2c6ca598e4f641b5bb8867b1080ffbfd78e65dc Mon Sep 17 00:00:00 2001 From: OG T Date: Fri, 10 Apr 2026 00:53:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(approval=5Fdb):=20update=5Ftelegram=5Fmessa?= =?UTF-8?q?ge=20=E7=94=A8=20raw=20SQL=20+=20CAST=20BIGINT=20=E9=81=BF?= =?UTF-8?q?=E5=85=8D=20int32=20overflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit telegram_chat_id 為 BIGINT (5619078117 > 2^31-1),SQLAlchemy ORM 會推斷為 $N::INTEGER 改用 raw SQL + CAST(:telegram_chat_id AS BIGINT) 繞過型別推斷 Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/services/approval_db.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/api/src/services/approval_db.py b/apps/api/src/services/approval_db.py index 11cec470..0a635006 100644 --- a/apps/api/src/services/approval_db.py +++ b/apps/api/src/services/approval_db.py @@ -619,16 +619,26 @@ class ApprovalDBService: 以 incident_id 查找最新 PENDING approval record 並回填。 """ async with get_db_context() as db: - values: dict = {"telegram_message_id": telegram_message_id} + # 2026-04-10 Claude Sonnet 4.6: 用 raw SQL 避免 SQLAlchemy 推斷 INTEGER + # telegram_chat_id 為 BIGINT,ORM update() 會誤用 $N::INTEGER 導致 int32 overflow + from sqlalchemy import text as _text + params: dict = { + "incident_id": incident_id, + "telegram_message_id": telegram_message_id, + "status": "PENDING", + } + chat_clause = "" if telegram_chat_id is not None: - values["telegram_chat_id"] = telegram_chat_id + params["telegram_chat_id"] = telegram_chat_id + chat_clause = ", telegram_chat_id = CAST(:telegram_chat_id AS BIGINT)" await db.execute( - update(ApprovalRecord) - .where( - ApprovalRecord.incident_id == incident_id, - ApprovalRecord.status == ApprovalStatus.PENDING, - ) - .values(**values) + _text(f""" + UPDATE approval_records + SET telegram_message_id = :telegram_message_id{chat_clause} + WHERE incident_id = :incident_id + AND status = :status + """), + params, ) # =========================================================================