A ConstraintViolation error arises when I try an import statement in py2neo, but this same error never appears when I import directly in neo4j's shell. I'm using the same exact statement in both, where in py2neo I simply use graph.cypher.execute(...). Note that I have multiple times ensured that each ID is unique -- there are no duplicate values.
py2neo.cypher.error.schema.ConstraintViolation: Node 0 already exists with label Employee and property "ID"=[XXXX]
With py2neo, even though the error is called and it ends the program, the entirety of the command still runs out, populating the graph just like it would in neo4j shell.
Question: How can I catch the error so that the rest of my import statements can run properly? I've tried catching the following without success: error.ConstraintViolation, error.schema.ConstraintViolation.
Moreover: The import continues after hitting that error which is great. However the import is continuing AFTER "continues" prints.
try:
graph.cypher.execute(statement)
except ConstraintViolation as e:
# print(traceback.format_exec())
print "ConstraintViolation error"
print "continues"
You need to import the ConstraintViolation properly and catch it:
from py2neo.cypher.error.schema import ConstraintViolation
import traceback
try:
# your cypher.execute() here
except ConstraintViolation as e:
# do whatever you want to do when the error occurs
# e.g. print the traceback of the error
print(traceback.format_exc())