fix(notif): 修复潜在的KeyError:index问题
This commit is contained in:
@@ -48,6 +48,10 @@ async def search_history(history: HistorySearchIn) -> HistorySearchOut:
|
||||
for date, users in data.items():
|
||||
for user, records in users.items():
|
||||
record = await Config.merge_statistic_info(records)
|
||||
# 安全检查:确保 index 字段存在
|
||||
if "index" not in record:
|
||||
logger.warning(f"合并统计信息缺少 index 字段,用户: {user}, 日期: {date}")
|
||||
record["index"] = []
|
||||
record["index"] = [HistoryIndexItem(**_) for _ in record["index"]]
|
||||
record = HistoryData(**record)
|
||||
data[date][user] = record
|
||||
|
||||
@@ -2272,7 +2272,12 @@ class AppConfig(GlobalConfig):
|
||||
|
||||
logger.success(f"统计信息合并完成, 共计 {len(data['index'])} 条记录")
|
||||
|
||||
return {k: v for k, v in data.items() if v}
|
||||
# 确保返回的字典始终包含 index 字段,即使为空
|
||||
result = {k: v for k, v in data.items() if v}
|
||||
if "index" not in result:
|
||||
result["index"] = []
|
||||
|
||||
return result
|
||||
|
||||
async def search_history(self, mode: str, start_date: date, end_date: date) -> dict:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user