Skip to content

Bug Report: graphify query crashes with ValueError #305

Closed

Description

@alice-0716-s

Bug Report: graphify query crashes with ValueError

Environment

  • graphifyy version: 0.3.29
  • Python version: 3.13.3
  • NetworkX version: 3.6.1
  • OS: macOS

Bug Description

The graphify query command crashes with a ValueError when trying to render query results.

Error Message

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.13/bin/graphify", line 7, in <module>
    sys.exit(main())
  File "/private/tmp/graphify-temp/graphify/__main__.py", line 828, in main
    print(_subgraph_to_text(G, nodes, edges, token_budget=budget))
          ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/graphify-temp/graphify/serve.py", line 95, in _subgraph_to_text
    d = G.edges[u, v]
        ~~~~~~~^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/networkx/classes/reportviews.py", line 1368, in __getitem__
    u, v, k = e
    ^^^^^^^
ValueError: not enough values to unpack (expected 3, got 2)

Root Cause

In serve.py line 95:

d = G.edges[u, v]

When the graph is a MultiGraph (which json_graph.node_link_graph creates by default when there are multiple edges between nodes), G.edges[u, v] returns a 3-tuple (u, v, key) instead of a 2-tuple.

The code at line 96 then tries to unpack it:

line = f"EDGE {sanitize_label(G.nodes[u].get('label', u))} --{d.get('relation', '')} [{d.get('confidence', '')}]--> {sanitize_label(G.nodes[v].get('label', v))}"

But d is not a dict when the graph is a MultiGraph.

Steps to Reproduce

  1. Install graphify: pip install graphifyy
  2. Create a graph.json with multiple edges between nodes (or any non-trivial graph)
  3. Run: graphify query "any query"

Workaround

Convert the graph to a regular Graph (non-MultiGraph) before saving:

G = nx.Graph(G)  # Remove parallel edges

Or modify _subgraph_to_text to handle MultiGraph edges properly.

Suggested Fix

Option 1: Handle MultiGraph explicitly:

if G.is_multigraph():
    d = G.edges[u, v, 0]  # Get first edge's data
else:
    d = G.edges[u, v]

Option 2: Convert to simple Graph in _load_graph:

G = json_graph.node_link_graph(data, edges="links")
if G.is_multigraph():
    G = nx.Graph(G)  # Convert to simple graph
return G

Additional Context

The graph.json was generated successfully by the /graphify skill. The issue only occurs during the query command when traversing edges.


Repository: https://github.com/safishamsi/graphify

Activity

  1. safishamsi commented on Apr 13, 2026

    @safishamsi
    Member

    Fixed in v0.4.11. Replaced G.edges[u, v] with G[u][v] and added a MultiGraph guard — if the loaded graph is a MultiGraph or MultiDiGraph, the first edge's attributes are used via next(iter(G[u][v].values()), {}).

    pip install --upgrade graphifyy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions