fix(approval_db): update_telegram_message 用 raw SQL + CAST BIGINT 避免 int32 overflow
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled

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 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-04-10 00:53:50 +08:00
parent dbb8104557
commit e2c6ca598e

View File

@@ -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 為 BIGINTORM 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,
)
# =========================================================================