mirror of
https://github.com/safishamsi/graphify.git
synced 2026-08-26 16:26:42 +00:00
fix(benchmark): guard against a node with a None label (#2674)
This commit is contained in:
@@ -39,7 +39,7 @@ def _query_subgraph_tokens(G: nx.Graph, question: str, depth: int = 3) -> int:
|
||||
terms = _query_terms(question)
|
||||
scored = []
|
||||
for nid, data in G.nodes(data=True):
|
||||
label = data.get("label", "").lower()
|
||||
label = (data.get("label") or "").lower()
|
||||
score = sum(1 for t in terms if t in label)
|
||||
if score > 0:
|
||||
scored.append((score, nid))
|
||||
|
||||
@@ -54,6 +54,21 @@ def test_query_keeps_short_non_english_terms():
|
||||
assert tokens > 0
|
||||
|
||||
|
||||
def test_query_handles_node_with_none_label():
|
||||
"""A node can carry `label` with a None VALUE, not just a missing key.
|
||||
|
||||
`.get("label", "")` only substitutes when the key is absent, so a stored
|
||||
None reached `.lower()` and raised
|
||||
`AttributeError: 'NoneType' object has no attribute 'lower'`. The loop
|
||||
scans every node before returning, so one such node broke the whole
|
||||
benchmark rather than just its own score.
|
||||
"""
|
||||
G = _make_graph()
|
||||
G.add_node("n6", label=None, source_file="orphan.py", source_location="L1", community=0)
|
||||
G.add_edge("n6", "n1", relation="calls", confidence="INFERRED")
|
||||
assert _query_subgraph_tokens(G, "how does authentication work") > 0
|
||||
|
||||
|
||||
# --- run_benchmark ---
|
||||
|
||||
def test_run_benchmark_returns_reduction(tmp_path):
|
||||
|
||||
Reference in New Issue
Block a user