Skip to content

wiki export: God Nodes index links both same-labeled god nodes to the first article, orphaning <Label>_2.md #3033

Closed

Description

@Heratiki

Summary

Same residual bug as #3032, but in the god-node path rather than the community path. When two god nodes share a display label — routine when the same class name exists in two modules — to_wiki writes two article files (Label.md and Label_2.md) with correct, distinct content, but the God Nodes section of index.md links both rows to Label.md. Label_2.md is orphaned.

Filed separately from #3032 because it is a different loop and a different index section; a fix to one does not fix the other. Both descend from #497 (closed), whose _unique_slug fix correctly stopped the file overwrites — #497 explicitly listed "two god nodes" and "a community and a god node" as affected. What survived is the index linking, not the file writing.

Repro

graphify 0.9.20, Python 3.14.

import networkx as nx, pathlib
from graphify.wiki import to_wiki

G = nx.Graph()
G.add_edges_from([("mod_a.py::GameState","a1"),("mod_a.py::GameState","a2"),
                  ("mod_b.py::GameState","b1"),("mod_b.py::GameState","b2")])
for n in G: G.nodes[n]["label"] = n.split("::")[-1]

communities = {0: list(G.nodes)}
god = [
    {"id": "mod_a.py::GameState", "label": "GameState", "degree": 2},
    {"id": "mod_b.py::GameState", "label": "GameState", "degree": 2},
]
to_wiki(G, communities, "wiki_god",
        community_labels={0: "Only Community"}, god_nodes_data=god)

print("files:", sorted(p.name for p in pathlib.Path("wiki_god").glob("*.md")))
for ln in pathlib.Path("wiki_god/index.md").read_text().splitlines():
    if "connections" in ln: print("   ", ln)

Output:

files: ['GameState.md', 'GameState_2.md', 'Only_Community.md', 'index.md']
    - [GameState](GameState.md) — 2 connections
    - [GameState](GameState.md) — 2 connections

Expected: the second row links to GameState_2.md.

Confirmed the two files are not identical — _unique_slug and the article renderer are both doing the right thing, so this is purely the index's link resolution.

Root cause

Identical shape to #3032. wiki.py:314-317 keeps the unique slug in a local and puts only the label in the resolver:

for node_data in god_nodes_data:
    nid = node_data.get("id")
    if nid and nid in G:
        slug = _unique_slug(_safe_filename(node_data['label']))
        god_articles.append((nid, slug))          # unique per node -- correct
        resolver.setdefault(node_data['label'], slug)   # label -> slug, first wins

wiki.py:330-332 writes each article from god_articles, which is why both files land correctly. But wiki.py:199 renders the index rows through the label-keyed resolver:

lines.append(f"- {_md_link(node['label'], resolver)} — {node['degree']} connections")

Suggested fix

god_articles already carries (node_id, slug) in the same order as god_nodes_data. Passing it into _index_md and linking by slug — rather than by label through resolver — fixes this without touching resolver or the dedup ordering that the wiki.py:298-301 comment depends on.

Impact in practice

Seen on a real 12,398-node graph: the God Nodes list showed GameState twice (1018 and 106 connections) and Entity twice, with every row pointing at the first article. Because god nodes are by definition the most-connected abstractions, the orphaned entry tends to be a load-bearing one.

Activity

  1. rohit-jsfreaky commented on Aug 25, 2026

    @rohit-jsfreaky
    Contributor

    Same fix as #3032. You were right that it is a separate loop, but both come down to _index_md resolving targets by label through the setdefault resolver instead of using the slug each article was actually written under — so it is one change to one function and I have put both in a single PR rather than split it.

    Your repro now prints GameState_2.md on the second row.

  2. safishamsi commented on Oct 12, 2026

    @safishamsi
    Member

    Fixed in v0.9.88 (graphifyy 0.9.88 on PyPI) via #3095.

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