Skip to content

fix(graph): preserve existing node ntype and props in add_node - #272

Merged
codeforstartups merged 1 commit into
codeforstartups:developmentfrom
Kaap10:fix/graph-node-metadata-loss
Oct 1, 2026
Merged

codeforstartups merged 1 commit into
codeforstartups:developmentfrom
Kaap10:fix/graph-node-metadata-loss

Conversation

@Kaap10

@Kaap10 Kaap10 commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes a critical data-loss bug in the Knowledge Graph layer where calling add_edge() or link_docs() inadvertently erased pre-existing node ntype and props metadata in DynamoDB.

Related issue

Fixes #271

Changes

  • src/dynavec/graph.py: Updated GraphStore.add_node() to conditionally set ntype and props using DynamoDB if_not_exists clauses instead of unconditionally replacing them with None / {}.
  • tests/test_graph_properties.py: Added unit tests verifying:
    • add_edge() and link_docs() preserve existing entity ntype and props.
    • Partial add_node() calls preserve unspecified node attributes.

Testing

  • Tests pass locally (pytest tests/test_graph_properties.py tests/test_graph_delete.py tests/test_graph_export.py — 32 passed)
  • Ruff checks pass
  • Documentation updated, if applicable

Checklist

  • My changes are focused and relevant to this pull request.
  • I have added or updated tests where appropriate.
  • I have reviewed my changes for unrelated modifications.
  • I have updated documentation where necessary.

Closes codeforstartups#271.

- Update GraphStore.add_node to use if_not_exists for ntype and props.
- Prevent add_edge and link_docs placeholder node initialization from erasing pre-existing entity metadata.
- Add unit tests verifying node metadata preservation across edge additions, doc linkages, and partial updates.
@codeforstartups

Copy link
Copy Markdown
Owner

Reviewed and verified — this is a real data-loss fix, nicely done. 🎯

add_edge() (graph.py:218-219) and link_docs() (graph.py:238) both call add_node(ns, id) with no ntype/props, so the old unconditional SET ntype = :t, props = :p silently reset an entity's type to None and its props to {} every time an edge or doc-link touched it. Switching the unspecified attributes to if_not_exists(...) preserves them, while an explicit value still overwrites — which your partial-update test pins down nicely.

The two new tests (test_add_edge_and_link_docs_preserve_existing_node_metadata, test_add_node_partial_update_preserves_unspecified_attributes) cover exactly the regression. All 4 CI checks green (ruff + strict mypy + pytest on 3.9/3.11/3.12). Merging. Thanks @Kaap10!

@codeforstartups
codeforstartups merged commit 044e27d into codeforstartups:development Oct 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Critical Data Loss in Knowledge Graph Layer - add_edge() and link_docs() erase existing entity ntype and props

2 participants