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

IndexEntryConflictException with apoc.merge.node #558

Closed
v2belleville opened this issue Dec 12, 2023 · 3 comments
Closed

IndexEntryConflictException with apoc.merge.node #558

v2belleville opened this issue Dec 12, 2023 · 3 comments

Comments

@v2belleville
Copy link

v2belleville commented Dec 12, 2023

apoc.merge.node returns an IndexEntryConflictException (see full error output below)

(t:Tweet {id:"1652044756417912836"}) does exists in the database but it is not the first id in the file that is in the db. why this one triggers the errors is a mystery. tried several time, it is this id that triggers the error every time. If I suppress it another, id further down the file triggers the same error

I'm apparently not the only one who faced that error (https://stackoverflow.com/questions/67507411/facing-indexentryconflictexception-while-merging) .
Since I'm not sure which directories are mentioned in the SO answer (I use a Windows Desktop version of Neo4j),
I tried dropping and reconstructing constraint and indexes but problem remains the same...

UPDATE: I just realize that the use of apoc here was a leftover from a previous more complex version of the query. in this case, a simple merge works like a charm, but I guess the apoc issue is worth fixing anyway...

`File ~\Desktop\Python\myTwitterJsonImport2Neo4j.py:156, in importJsonTwLst(jsonTwLst, twExportDate, label, twOrigine, check, src)
149 #print(twLstNoNull)
151 query="""unwind $twLst as twJson
152 match (u:TwUser {id:twJson.userId})
153 call apoc.merge.node(['Tweet'],twJson) yield node
154 with twJson,u,node where not exists((u)-[:TWEETED]->(node))
155 create (u)-[:TWEETED {twExportDate:twJson.twExportDate, importDateTime:localdatetime({ timezone: 'Europe/Paris' })}]->(node)"""
--> 156 res=Neo.session.run(query,twLst=twLstNoNull)
157 print(res.consume().counters)
159 # creation des tw RT

File C:\Program Files\Python311\Lib\site-packages\neo4j_sync\work\session.py:311, in Session.run(self, query, parameters, **kwargs)
309 bookmarks = self._get_bookmarks()
310 parameters = dict(parameters or {}, **kwargs)
--> 311 self._auto_result._run(
312 query, parameters, self._config.database,
313 self._config.impersonated_user, self._config.default_access_mode,
314 bookmarks, self._config.notifications_min_severity,
315 self._config.notifications_disabled_categories,
316 )
318 return self._auto_result

File C:\Program Files\Python311\Lib\site-packages\neo4j_sync\work\result.py:166, in Result._run(self, query, parameters, db, imp_user, access_mode, bookmarks, notifications_min_severity, notifications_disabled_categories)
164 self._pull()
165 self._connection.send_all()
--> 166 self._attach()

File C:\Program Files\Python311\Lib\site-packages\neo4j_sync\work\result.py:274, in Result._attach(self)
272 if self._exhausted is False:
273 while self._attached is False:
--> 274 self._connection.fetch_message()

File C:\Program Files\Python311\Lib\site-packages\neo4j_sync\io_common.py:180, in ConnectionErrorHandler.getattr..outer..inner(*args, **kwargs)
178 def inner(*args, **kwargs):
179 try:
--> 180 func(*args, **kwargs)
181 except (Neo4jError, ServiceUnavailable, SessionExpired) as exc:
182 assert not asyncio.iscoroutinefunction(self.__on_error)

File C:\Program Files\Python311\Lib\site-packages\neo4j_sync\io_bolt.py:808, in Bolt.fetch_message(self)
804 # Receive exactly one message
805 tag, fields = self.inbox.pop(
806 hydration_hooks=self.responses[0].hydration_hooks
807 )
--> 808 res = self._process_message(tag, fields)
809 self.idle_since = perf_counter()
810 return res

File C:\Program Files\Python311\Lib\site-packages\neo4j_sync\io_bolt5.py:352, in Bolt5x0._process_message(self, tag, fields)
350 self._server_state_manager.state = self.server_states.FAILED
351 try:
--> 352 response.on_failure(summary_metadata or {})
353 except (ServiceUnavailable, DatabaseUnavailable):
354 if self.pool:

File C:\Program Files\Python311\Lib\site-packages\neo4j_sync\io_common.py:247, in Response.on_failure(self, metadata)
245 handler = self.handlers.get("on_summary")
246 Util.callback(handler)
--> 247 raise Neo4jError.hydrate(**metadata)

ClientError: {code: Neo.ClientError.Procedure.ProcedureCallFailed} {message: Failed to invoke procedure apoc.merge.node: Caused by: IndexEntryConflictException{propertyValues=( String("1652044756417912836") ), addedEntityId=-1, existingEntityId=2328}}`

@gem-neo4j
Copy link
Contributor

Hey! Can you let me know which APOC and Neo4j version you are working with, and are you able to provide us a dataset or a simpler reproduction set? Thanks :)

@v2belleville
Copy link
Author

Neo4j and APOC are 5.11.0 (Windows Desktop)

but since it's been 3 weeks, I'm afraid I won't have the time to dig into this to remember which data file triggered the error (as mentioned, I'm not using APOC for this anymore) . will update if I run into the issue again

@gem-neo4j
Copy link
Contributor

I have tried reproducing this, but can't. One suspicion is that you are only using the identProps here and should be using the other arguments as well:

apoc.merge.nodes(labels, identProps, onCreateProps, onMatchProps) is the signature, where the last 2 args are optional.

This means that the identProps are the ones that match, and if a node with exactly those props is not found, then a new one is created.

Here: call apoc.merge.node(['Tweet'],twJson) yield node the twJson must then only contain matching data. If you are intending to match on id and then in match/create update the node, you would need to write: call apoc.merge.node(['Tweet'],{id: twJson.id}, twJson, twJson) yield node

Although, Cypher now has support for dynamic labels, so if my above suspicion is wrong, then my recommended solution is to use only Cypher:

MERGE (:$())

I understand the original author of this issue rewrote APOC out of the query, but if the above doesn't fix the issue for anyone else arriving here, reopen with a reproducible case for us to work with :) thanks!

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

No branches or pull requests

2 participants