From c8558cda9e1e44feff5d98f884c54c620bb9bf1b Mon Sep 17 00:00:00 2001 From: OG T Date: Mon, 23 Mar 2026 23:09:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20resolve=20=E6=99=82=20DB=20?= =?UTF-8?q?=E8=A8=98=E9=8C=84=E4=B8=8D=E5=AD=98=E5=9C=A8=E8=A6=96=E7=82=BA?= =?UTF-8?q?=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: Incident 可能因 DB 寫入失敗只存在於 Redis 修復: 只要 Redis 更新成功就算成功 (API 只讀 Redis) Co-Authored-By: Claude Opus 4.5 --- apps/api/src/services/proposal_service.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/api/src/services/proposal_service.py b/apps/api/src/services/proposal_service.py index 20390644..2b7cd85c 100644 --- a/apps/api/src/services/proposal_service.py +++ b/apps/api/src/services/proposal_service.py @@ -569,7 +569,7 @@ class ProposalService: error=str(e), ) - # 2. 更新 DB + # 2. 更新 DB (如果存在) try: async with get_db_context() as db: stmt = select(IncidentRecord).where( @@ -586,6 +586,15 @@ class ProposalService: "resolve_incident_db_updated", incident_id=incident_id, ) + else: + # DB 沒有記錄但 Redis 有 - 這是可接受的狀態 + # (Incident 可能因 DB 寫入失敗只存在 Redis) + db_ok = True # 視為成功,因為沒有需要更新的記錄 + logger.warning( + "resolve_incident_db_not_found", + incident_id=incident_id, + note="Incident exists in Redis but not in DB, this is acceptable", + ) except Exception as e: logger.exception( "resolve_incident_db_error", @@ -593,7 +602,8 @@ class ProposalService: error=str(e), ) - success = redis_ok and db_ok + # 只要 Redis 更新成功就算成功(API 只讀 Redis) + success = redis_ok logger.info( "resolve_incident_completed", incident_id=incident_id,