apoc icon indicating copy to clipboard operation
apoc copied to clipboard

Update example in docs for apoc.trigger.add

Open neo-technology-build-agent opened this issue 2 years ago • 2 comments

Issue by stuartlaurie Monday Mar 02, 2020 at 17:22 GMT Originally opened as https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/1435


How to Reproduce the Problem

On this page: http://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/operational/triggers/

the example gives:

CALL apoc.trigger.add("forceStringType",
"UNWIND apoc.trigger.propertiesByKey({assignedNodeProperties}, 'reference') AS prop
CALL apoc.util.validate(apoc.meta.type(prop) <> 'STRING', 'expected string property type, got %s', [apoc.meta.type(prop)]) RETURN null", {phase:'before'})

But when it runs we get:

Error executing triggers {forceStringType=Failed to invoke procedure apoc.util.validate: Caused by: java.lang.RuntimeException: expected string property type, got MAP}

If i return prop I get:

{node=Node[21], new=thing, old=null, key=reference}

So, it looks like the example should be updated to e.g.

changing the check to prop.new

CALL apoc.trigger.add("forceStringType",UNWIND apoc.trigger.propertiesByKey({assignedNodeProperties}, 'reference') AS prop CALL apoc.util.validate(apoc.meta.type(prop.new) <> 'STRING', 'expected string property type, got %s', [apoc.meta.type(prop.new)]) RETURN null

Versions

Neo4j Enterprise 3.5.15 with latest APOC