fix(api): 活躍事件 500 錯誤修復 (timezone 比較)

根因: incidents.sort() 比較 timezone-aware 與 naive datetime
錯誤: can't compare offset-naive and offset-aware datetimes

修復: safe_created_at() 統一轉換為 timestamp

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-03-26 18:48:34 +08:00
parent f1117a3e79
commit a3a50fa807

View File

@@ -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 = []