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) <noreply@anthropic.com>
This commit is contained in:
Safi
2026-06-17 13:49:31 +01:00
co-authored by Claude Opus 4.8
parent 2c662c7917
commit 9c8bd4d47c
2 changed files with 20 additions and 0 deletions
+7
View File
@@ -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
+13
View File
@@ -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):