Prevent duplicate relationships; harden tree render against cycles #34
Reference in New Issue
Block a user
Delete Branch "prevent-duplicate-links"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
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>