fix(memory): use explicit None checks and remove unnecessary Optional type

- Replace truthiness checks with 'is not None' for data.message in graph_data and community_graph endpoints to handle empty string correctly
- Remove Optional wrapper from GraphStatistics.edge_types since it already has a default_factory
This commit is contained in:
lanceyq
2026-04-27 18:39:33 +08:00
parent 9a5ce7f7c6
commit 2fa4d29548
2 changed files with 3 additions and 3 deletions

View File

@@ -350,7 +350,7 @@ async def get_graph_data_api(
)
# 检查是否有错误消息
if data.message and data.statistics.total_nodes == 0:
if data.message is not None and data.statistics.total_nodes == 0:
api_logger.warning(f"图数据查询返回空结果: {data.message}")
return success(data=data.model_dump(), msg=data.message)
@@ -394,7 +394,7 @@ async def get_community_graph_data_api(
message=result.get("message"),
)
if data.message and data.statistics.total_nodes == 0:
if data.message is not None and data.statistics.total_nodes == 0:
api_logger.warning(f"社区图谱查询返回空结果: {data.message}")
return success(data=data.model_dump(), msg=data.message)

View File

@@ -99,7 +99,7 @@ class GraphStatistics(BaseModel):
total_nodes: int = Field(0, description="节点总数")
total_edges: int = Field(0, description="边总数")
node_types: Dict[str, int] = Field(default_factory=dict, description="各节点类型数量")
edge_types: Optional[Dict[str, int]] = Field(default_factory=dict, description="各边类型数量")
edge_types: Dict[str, int] = Field(default_factory=dict, description="各边类型数量")
class GraphData(BaseModel):