diff --git a/apps/api/src/api/v1/incidents.py b/apps/api/src/api/v1/incidents.py index c4cb154ee..f9deb5ceb 100644 --- a/apps/api/src/api/v1/incidents.py +++ b/apps/api/src/api/v1/incidents.py @@ -130,7 +130,18 @@ async def list_incidents() -> IncidentListResponse: incidents = await incident_service.get_active_incidents() # 按時間排序 (最新優先) - incidents.sort(key=lambda i: i.created_at, reverse=True) + # 2026-03-26 修復: 處理 timezone-aware 與 naive datetime 混合問題 + from datetime import UTC + + def safe_created_at(i: Incident) -> float: + """安全取得 timestamp,處理 timezone 混合問題""" + dt = i.created_at + if dt.tzinfo is None: + # naive datetime 假設為 UTC + dt = dt.replace(tzinfo=UTC) + return dt.timestamp() + + incidents.sort(key=safe_created_at, reverse=True) # Phase 6.5: 為每個事件生成決策令牌 (非同步並行) responses = []