Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apoc.refactor.mergeNodes throws IndexEntryConflictException when merged nodes have relationships with UNIQUE constraint #699

Closed
michalkurzeja opened this issue Dec 5, 2024 · 3 comments · Fixed by #703
Assignees
Labels
bug Something isn't working

Comments

@michalkurzeja
Copy link

michalkurzeja commented Dec 5, 2024

I discovered this when trying to merge nodes using apoc.refactor.mergeNodes procedure.
If a node I'm merging has a relationship of type with a unique constraint, then the merger operation fails with IndexEntryConflictException.

Neo4j Version: 5.25.1 + APOC 5.25.1
Operating System: macOS 15.1.1
API: Docker

Steps to reproduce

  1. Start with an empty DB.
  2. Run the following to create the constraint and populate the DB with some nodes and relationships:
CREATE CONSTRAINT foo_uniq FOR ()-[r:MY_REL]-() REQUIRE r.foo IS UNIQUE;
CREATE
    (n1 {name: "n1"})-[r1:MY_REL {foo: "a"}]->(n2 {name: "n2"}),
    (n3 {name: "n3"})-[r2:MY_REL {foo: "b"}]->(n4 {name: "n4"});
  1. Attempt to merge nodes n1 and n3:
MATCH (n1 {name: "n1"}), (n3 {name: "n3"})
CALL apoc.refactor.mergeNodes([n1, n3]) YIELD node
FINISH

Expected behavior

Nodes are merged and we're left with:
(n1)-[r1]->(n2)
(n1)-[r2]->(n4)

This is what happens if foo_uniq constraint is not present.

Actual behavior

The query returns:

Failed to invoke procedure apoc.refactor.mergeNodes: Caused by: IndexEntryConflictException{propertyValues=( String("b") ), addedEntityId=-1, existingEntityId=1}

@michalkurzeja michalkurzeja added the bug Something isn't working label Dec 5, 2024
@mnd999 mnd999 transferred this issue from neo4j/neo4j Dec 6, 2024
@loveleif
Copy link
Contributor

loveleif commented Dec 9, 2024

@michalkurzeja thanks for the, well written, report and sorry for the inconvenience! A fix is on the way, I discovered that this is not the only refactor procedure that suffers from this bug.

@loveleif loveleif self-assigned this Dec 9, 2024
@michalkurzeja
Copy link
Author

Awesome, thanks for the quick check-up and the reply! Looking forward to the fix :)

@loveleif
Copy link
Contributor

Sorry for the delay, it's merged now and expected to be released with the next version of Neo4j.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants