File tree Expand file tree Collapse file tree
tests/integration/adapters Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,6 +72,23 @@ def test_upsert_nodes_idempotent(store, tag):
7272 assert len (found ) == 1
7373
7474
75+ def test_upsert_relations_idempotent (store , tag ):
76+ """Upserting the same relation twice must produce exactly one edge (MERGE idempotent)."""
77+ src = EntityNode (label = "LIIdempRel" , name = f"IdempSrc-{ tag } " )
78+ dst = EntityNode (label = "LIIdempRel" , name = f"IdempDst-{ tag } " )
79+ store .upsert_nodes ([src , dst ])
80+
81+ rel = Relation (label = "LI_IDEMP_REL" , source_id = src .id , target_id = dst .id )
82+ store .upsert_relations ([rel ])
83+ store .upsert_relations ([rel ]) # second call must not duplicate
84+
85+ rows = store ._client .cypher (
86+ "MATCH (a {id: $src})-[r:LI_IDEMP_REL]->(b {id: $dst}) RETURN count(r) AS cnt" ,
87+ params = {"src" : src .id , "dst" : dst .id },
88+ )
89+ assert rows [0 ]["cnt" ] == 1 , f"expected exactly 1 edge after double upsert, got: { rows } "
90+
91+
7592def test_get_by_id (store , tag ):
7693 node = EntityNode (label = "LIGetById" , name = f"ById-{ tag } " )
7794 node_id = node .id
You can’t perform that action at this time.
0 commit comments