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:
@@ -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)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user