From 9c8bd4d47c10ea199c6a7775aa352740102dd835 Mon Sep 17 00:00:00 2001 From: Safi Date: Wed, 17 Jun 2026 13:49:31 +0100 Subject: [PATCH] Populate Obsidian canvas when no community data is present (#1324) to_canvas built cards solely by iterating communities, so a graph with no community data (--no-cluster builds, or a missing analysis sidecar) wrote the empty 32-byte {"nodes":[],"edges":[]} shell while notes rendered fine. Fall back to one synthetic community covering every node so the canvas reflects the graph. Co-Authored-By: Claude Opus 4.8 (1M context) --- graphify/export.py | 7 +++++++ tests/test_export.py | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/graphify/export.py b/graphify/export.py index 50faa50d1..86ad6a99e 100644 --- a/graphify/export.py +++ b/graphify/export.py @@ -1127,6 +1127,13 @@ def to_canvas( seen_names[base] = 0 node_filenames[node_id] = base + # Fallback: with no community data (e.g. --no-cluster builds or a missing + # analysis sidecar) the grid below produces nothing and the canvas is written + # as an empty 32-byte shell on an otherwise populated graph. Emit every node + # into one synthetic community so the canvas always reflects the graph (#1324). + if not communities and G.number_of_nodes() > 0: + communities = {0: [str(n) for n in G.nodes()]} + num_communities = len(communities) cols = math.ceil(math.sqrt(num_communities)) if num_communities > 0 else 1 rows = math.ceil(num_communities / cols) if num_communities > 0 else 1 diff --git a/tests/test_export.py b/tests/test_export.py index 65964d24e..050e32e4b 100644 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -180,6 +180,19 @@ def test_to_canvas_file_paths_relative_to_vault(): assert node["file"].endswith(".md") +def test_to_canvas_no_communities_still_populates(): + """#1324: empty communities (e.g. --no-cluster builds) on a populated graph + must NOT produce the 32-byte empty `{"nodes": [], "edges": []}` shell.""" + G = make_graph() + with tempfile.TemporaryDirectory() as tmp: + out = Path(tmp) / "graph.canvas" + to_canvas(G, {}, str(out)) # no community data — the bug condition + data = json.loads(out.read_text()) + assert len(data["nodes"]) >= G.number_of_nodes() + assert len(data["edges"]) >= 1 + assert out.stat().st_size > 32 + + # ── Issue #834: backup_if_protected ────────────────────────────────────────── def test_backup_no_graph_json(tmp_path):