activegraph icon indicating copy to clipboard operation
activegraph copied to clipboard

Missing error handling when there is a node property existence constraint

Open kapone89 opened this issue 3 years ago • 0 comments

When I add a node property existence constraint to the database and try to create invalid node using the ActiveNode model, there is no error and new object is returned. However the node is not created.

Code example (inline, gist, or repo)

Neo4j::ActiveBase.current_session.query "CREATE CONSTRAINT ON (n:Bug) ASSERT n.uuid IS UNIQUE"
Neo4j::ActiveBase.current_session.query "CREATE CONSTRAINT ON (n:Bug) ASSERT exists(n.desc)"

class Bug
  include Neo4j::ActiveNode
end

# using raw query
Neo4j::ActiveBase.current_session.query "CREATE (b:Bug)"
CYPHER CREATE (b:Bug) 
Neo4j::Core::CypherSession::SchemaErrors::ConstraintValidationFailedError:   Cypher error: Neo.ClientError.Schema.ConstraintValidationFailed: org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException: Node(3666) with label `Bug` must have the property `desc`

# using ActiveNode
b = Bug.create!
CYPHER CREATE (n:`Bug`) SET n = {props} RETURN n | {:props=>{:uuid=>"238996bb-65a9-479a-bdb1-cf58a1025fb5"}}
=> #<Bug uuid: "238996bb-65a9-479a-bdb1-cf58a1025fb5">

# however the node is not created
Bug.count
CYPHER MATCH (n:`Bug`) RETURN count(n) AS count
=> 0

Runtime information:

Neo4j database version: 3.5.16-enterprise neo4j gem version: 9.6.2 neo4j-core gem version: 9.0.0

kapone89 avatar Sep 23 '20 12:09 kapone89