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 3 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

Comment by Mike-Rossi Tuesday Jul 14, 2020 at 16:00 GMT


Hi, how were you able to return prop? I'm not sure what apoc function to use.

Comment by vga91 Wednesday Oct 13, 2021 at 09:52 GMT


@stuartlaurie Sorry if I not understood, but it seems that the example works. That is, if I execute:

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'})

and after that:

CREATE (a:Node) SET a.reference = 1

I receive:

Neo.ClientError.Transaction.TransactionHookFailed

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

as in the documentation, because is an integer. The prop.new should depend on dataset.

Closing as this example no longer exists in the docs.

gem-neo4j avatar Dec 05 '24 08:12 gem-neo4j