Prevent duplicate relationships; harden tree render against cycles #34

Merged
justin merged 1 commits from prevent-duplicate-links into main 2026-06-08 11:35:12 -04:00
Owner

create_relationship rejects equivalent edges (409) so no double-linking. Tree view sanitizes the graph (dedupe, drop self-links, break ancestor cycles) and never blank-crashes. Person page shows the 409. 59 tests pass.

create_relationship rejects equivalent edges (409) so no double-linking. Tree view sanitizes the graph (dedupe, drop self-links, break ancestor cycles) and never blank-crashes. Person page shows the 409. 59 tests pass.
justin added 1 commit 2026-06-08 11:35:12 -04:00
Root cause of the blank Jung tree: a child double-linked to the same parent
(and, generally, any cycle) made family-chart recurse forever.

Backend (the real fix):
- create_relationship now rejects an equivalent existing edge → 409.
  parent_child is directional (parent→child); partnership/sibling match the
  pair in either order. So you can't link the same two people the same way
  twice. (GEDCOM import already deduped; manual creates didn't.)

Frontend (defense in depth so data can never blank the view):
- Tree view sanitizes the graph before rendering: dedupes parents/spouses,
  drops self-links, and greedily breaks ancestor cycles (a person can't be
  their own ancestor); children are derived from the kept edges. The render is
  wrapped in try/catch and shows a note instead of a blank canvas, telling you
  which conflicting links were skipped.
- Person page surfaces the 409 ("They're already linked that way.").

59 backend tests pass (incl. dup-rejection + reverse-parent-child allowed).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
justin merged commit 8c36785197 into main 2026-06-08 11:35:12 -04:00
justin deleted branch prevent-duplicate-links 2026-06-08 11:35:13 -04:00
Sign in to join this conversation.