Skip to content

Commit 1a03304

Browse files
committed
[bugfix][when extra is '']
1 parent db6d038 commit 1a03304

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

muagent/db_handler/graph_db_handler/geabase_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def decode_vertex(self, col_data, k) -> Dict:
396396
vertextVal = col_data.get("vertexVal", {})
397397
node_val_json = {
398398
**{"ID": int(vertextVal.get("id", "")), "type": vertextVal.get("type", "")},
399-
**{k: v.get("strVal", "") or v.get("intVal", "0") for k, v in vertextVal.get("props", {}).items()}
399+
**{k: v.get("strVal", "") if "strVal" in v else v.get("intVal", "0") for k, v in vertextVal.get("props", {}).items()}
400400
}
401401
node_val_json.pop("biz_node_id", "")
402402
return node_val_json
@@ -406,7 +406,7 @@ def _decode_edge(data):
406406
edgeVal= data.get("edgeVal", {})
407407
edge_val_json = {
408408
**{"SRCID": int(edgeVal.get("srcId", "")), "DSTID": int(edgeVal.get("dstId", "")), "type": edgeVal.get("type", "")},
409-
**{k: v.get("strVal", "") or v.get("intVal", "0") for k, v in edgeVal.get("props", {}).items()}
409+
**{k: v.get("strVal", "") if "strVal" in v else v.get("intVal", "0") for k, v in edgeVal.get("props", {}).items()}
410410
}
411411
# 存在业务逻辑
412412
edge_val_json["start_id"] = edge_val_json.pop("original_src_id1__")

muagent/service/ekg_construct/ekg_construct_base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def update_edges(self, edges: List[GEdge], teamid: str):
408408

409409
def get_node_by_id(self, nodeid: str, node_type:str = None) -> GNode:
410410
node = self.gb.get_current_node({'id': nodeid}, node_type=node_type)
411-
extra_attrs = json.loads(node.attributes.pop("extra", "{}"))
411+
extra_attrs = json.loads(node.attributes.pop("extra", "{}") or "{}")
412412
node.attributes.update(extra_attrs)
413413
return node
414414

@@ -418,10 +418,10 @@ def get_graph_by_nodeid(self, nodeid: str, node_type: str, teamid: str=None, hop
418418
# filter the node which dont match teamid
419419
result = self.gb.get_hop_infos({'id': nodeid}, node_type=node_type, hop=hop)
420420
for node in result.nodes:
421-
extra_attrs = json.loads(node.attributes.pop("extra", "{}"))
421+
extra_attrs = json.loads(node.attributes.pop("extra", "{}") or "{}")
422422
node.attributes.update(extra_attrs)
423423
for edge in result.edges:
424-
extra_attrs = json.loads(edge.attributes.pop("extra", "{}"))
424+
extra_attrs = json.loads(edge.attributes.pop("extra", "{}") or "{}")
425425
edge.attributes.update(extra_attrs)
426426
return result
427427

@@ -463,18 +463,18 @@ def search_nodes_by_text(self, text: str, node_type: str = None, teamid: str = N
463463
nodes_by_desc = self.gb.get_current_nodes({"description": text}, node_type=node_type)
464464
nodes = self.gb.get_nodes_by_ids(nodeids)
465465
for node in nodes:
466-
extra_attrs = json.loads(node.attributes.pop("extra", "{}"))
466+
extra_attrs = json.loads(node.attributes.pop("extra", "{}") or "{}")
467467
node.attributes.update(extra_attrs)
468468
return nodes_by_name + nodes_by_desc + nodes
469469

470470
def search_rootpath_by_nodeid(self, nodeid: str, node_type: str, rootid: str) -> Graph:
471471
# rootid = f"{teamid}" # todo check the rootid
472472
result = self.gb.get_hop_infos({"id": nodeid}, node_type=node_type, hop=15, reverse=True)
473473
for node in result.nodes:
474-
extra_attrs = json.loads(node.attributes.pop("extra", "{}"))
474+
extra_attrs = json.loads(node.attributes.pop("extra", "{}") or "{}")
475475
node.attributes.update(extra_attrs)
476476
for edge in result.edges:
477-
extra_attrs = json.loads(edge.attributes.pop("extra", "{}"))
477+
extra_attrs = json.loads(edge.attributes.pop("extra", "{}") or "{}")
478478
edge.attributes.update(extra_attrs)
479479

480480
# paths must be ordered from start to end

tests/service/ekg_construct_test_2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,5 @@ def generate_edge(node1, node2):
247247
print(len(nodes))
248248

249249
# search path by node and rootid
250-
graph = ekg_construct_service.search_rootpath_by_nodeid(nodeid="shanshi_opsgptkg_analysis_3", node_type="opsgptkg_analysis", rootid="shanshi_opsgptkg_intent_0")
250+
graph = ekg_construct_service.search_rootpath_by_nodeid(nodeid="shanshi_opsgptkg_analysis_2", node_type="opsgptkg_analysis", rootid="shanshi_opsgptkg_intent_0")
251251
print(len(graph.nodes), len(graph.edges))

0 commit comments

Comments
 (0)