Skip to content

graphify explain/path still crash on MultiGraph edge access #796

Closed

Description

@gudzenkov

Summary

graphify explain and some path/MCP edge-rendering paths still access edges as if the graph is always a simple Graph:

edata = G.edges[nid, nb]
edata = G.edges[u, v]

When graph.json has already loaded successfully as a NetworkX MultiGraph / MultiDiGraph, this crashes during rendering with:

ValueError: not enough values to unpack (expected 3, got 2)

This issue is not about the edges/links node-link key mismatch. That was a separate loader/schema compatibility bug. The failure reported here happens after the graph loads and is specifically about MultiGraph edge access.

This is the same bug class as #305, but #305's v0.4.11 fix was applied to _subgraph_to_text() / query rendering only, not all CLI/MCP call sites.

Environment

  • Package: graphifyy
  • Version: 0.7.11
  • Python: 3.14 via uv run --with graphifyy==0.7.11
  • NetworkX: version installed by graphifyy==0.7.11
  • OS/runtime: Linux aarch64

Reproduction

Use any node-link graph.json that NetworkX loads as a multigraph, for example one with multigraph: true or parallel edges between the same source/target pair.

Then run:

uv run --with graphifyy==0.7.11 graphify explain "REQ-003: Document And PPM Generation" --graph graph.json

Observed output:

Node: REQ-003: Document And PPM Generation
  ID:        req_003_document_ppm_generation
  Source:    architecture/feature/req-003-document-and-ppm-generation.md None
  Type:      document
  Community:
  Degree:    1

Connections (1):
Traceback (most recent call last):
  File ".../bin/graphify", line 10, in <module>
    sys.exit(main())
  File ".../site-packages/graphify/__main__.py", line 1558, in main
    edata = G.edges[nid, nb]
            ~~~~~~~^^^^^^^^^
  File ".../site-packages/networkx/classes/reportviews.py", line 1368, in __getitem__
    u, v, k = e
ValueError: not enough values to unpack (expected 3, got 2)

I also see the same simple-Graph access pattern in path rendering:

# graphify/__main__.py path/explain call sites in v0.7.11
edata = G.edges[u, v]
edata = G.edges[nid, nb]

Expected behavior

All CLI/MCP graph operations should handle both simple graphs and multigraphs consistently.

For a MultiGraph/MultiDiGraph, edge data access should use G[u][v] and select one or iterate all parallel edge attribute dicts.

Likely fix

Centralize edge-data access in a helper and replace direct G.edges[u, v] / G.edges[nid, nb] lookups:

def _edge_data_for_pair(G, u, v):
    raw = G[u][v]
    if isinstance(G, (nx.MultiGraph, nx.MultiDiGraph)):
        return next(iter(raw.values()), {})
    return raw

For commands that should show all relations, use an iterator instead:

def _edge_datas_for_pair(G, u, v):
    raw = G[u][v]
    if isinstance(G, (nx.MultiGraph, nx.MultiDiGraph)):
        return list(raw.values())
    return [raw]

Then explain can either print the first edge or all parallel relations.

Related

Activity

  1. safishamsi commented on May 9, 2026

    @safishamsi
    Member

    Fixed in v0.7.12 — added edge_data(G, u, v) helper in build.py that handles both nx.Graph and nx.MultiGraph/nx.MultiDiGraph. All call sites in serve.py, wiki.py, export.py, analyze.py, and benchmark.py updated.

  2. added a commit that references this issue on May 13, 2026
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