fix(hql): UpsertE ignoring From()/To() parameters - Issue #850 #852
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
UpsertE was incorrectly using the first edge from the source iterator instead of looking up edges by the specified from_node/to_node parameters.
Fixes #850
Greptile Overview
Greptile Summary
Fixed a critical bug in
UpsertEwhere it incorrectly used the first edge from the source iterator instead of looking up edges by the specifiedfrom_node/to_node/labelparameters.Key Changes:
upsert_e()inupsert.rs:353-520to query the database directly using edge endpoints rather than relying on iterator contentout_edges_dbbyfrom_node+label_hash, then filters by matchingto_nodemutmodifier fromselfparameter since the iterator is no longer consumedtest_upsert_e_ignores_iterator_content()to reflect the new behavior where iterator content is completely ignoredtest_upsert_e_creates_edge_between_correct_nodes_issue_850andtest_upsert_e_updates_correct_edge_when_multiple_edges_exist_issue_850) that verify the fixImpact:
This fix ensures that
UpsertEoperations target the correct edges based on their endpoints, preventing accidental updates to unrelated edges. The change makes the behavior more predictable and aligns with the semantic meaning of thefrom_nodeandto_nodeparameters.Important Files Changed
upsert_eto lookup edges byfrom_node/to_node/labelinstead of using source iterator, resolving Issue #850Sequence Diagram
sequenceDiagram participant Client participant UpsertE as upsert_e() participant Storage as HelixGraphStorage participant OutEdgesDB as out_edges_db participant EdgesDB as edges_db participant InEdgesDB as in_edges_db Note over Client,InEdgesDB: Before Fix (Issue #850) Client->>UpsertE: upsert_e(label, from_node, to_node, props) UpsertE->>UpsertE: Get first edge from iterator Note over UpsertE: ❌ Ignores from_node/to_node parameters! UpsertE->>EdgesDB: Update wrong edge UpsertE-->>Client: Return incorrect edge Note over Client,InEdgesDB: After Fix (Current) Client->>UpsertE: upsert_e(label, from_node, to_node, props) Note over UpsertE: ✓ Ignores iterator content UpsertE->>UpsertE: hash_label(label) UpsertE->>OutEdgesDB: get_duplicates(from_node + label_hash) OutEdgesDB-->>UpsertE: Iterator of edges UpsertE->>UpsertE: Filter by to_node match alt Edge exists UpsertE->>Storage: get_edge(edge_id) Storage-->>UpsertE: existing_edge UpsertE->>UpsertE: Merge properties UpsertE->>EdgesDB: put(updated_edge) UpsertE-->>Client: Return updated edge else Edge does not exist UpsertE->>UpsertE: Create new edge UpsertE->>EdgesDB: put(new_edge) UpsertE->>OutEdgesDB: put(from_node mapping) UpsertE->>InEdgesDB: put(to_node mapping) UpsertE-->>Client: Return new edge end