From 43a370fc113d747d24009a9aba5af02f465e9451 Mon Sep 17 00:00:00 2001 From: OG T Date: Wed, 1 Apr 2026 18:03:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(model):=20IncidentOutcome=20=E8=88=8A=20Red?= =?UTF-8?q?is=20=E5=AD=97=E4=B8=B2=E6=A0=BC=E5=BC=8F=E7=9B=B8=E5=AE=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 舊事件 outcome 存為字串 "resolved",Pydantic v2 無法解析 → INTERNAL_ERROR on /auto-repair/evaluate/{incident_id} field_validator mode='before' 將字串轉為 None (安全丟棄) 確保舊資料不引發 incident_parse_error Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/models/incident.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/api/src/models/incident.py b/apps/api/src/models/incident.py index 8acfe69a..98352400 100644 --- a/apps/api/src/models/incident.py +++ b/apps/api/src/models/incident.py @@ -25,7 +25,7 @@ from enum import Enum from typing import Literal from uuid import UUID, uuid4 -from pydantic import BaseModel, Field +from pydantic import BaseModel, Field, field_validator # 復用現有模型 (避免重複定義) from src.models.approval import BlastRadius @@ -419,6 +419,14 @@ class Incident(BaseModel): # [首席架構師] 移除 json_encoders (Pydantic v2 已 deprecated),原生序列化輸出格式與 .isoformat() 一致 v1.1 2026-04-01 Asia/Taipei + # 2026-04-01 Claude Code: 舊 Redis 資料相容性 - outcome 可能存為字串 "resolved" + @field_validator("outcome", mode="before") + @classmethod + def coerce_outcome_string(cls, v: object) -> object: + if isinstance(v, str): + return None # 舊格式字串無法還原為 IncidentOutcome,捨棄即可 + return v + # ============================================================================= # DTOs (Data Transfer Objects)