I am using the python bolt driver to create nodes in a neo4j database. These nodes get altered by apoc.trigger
functions. And i want the returning BoltStatementResult
to contain the altered version of these nodes.
This is what i have tested so far:
My trigger function:
CALL apoc.trigger.add(
'onCreateNodeAddMetadata',
'UNWIND {createdNodes} AS n
SET n.uid = apoc.create.uuid(), n.timestamp = timestamp() RETURN n',
{phase: 'before'}
)
I expect the returning value of my session.write_transaction
to contain the the added properties.
As a safe workaround (but see caveat below), the Cypher query in your write_transaction
can return the native ID of the created node (e.g., RETURN ID(n)
).
Then, as long as you know the node was not deleted, you can perform a query for it with that ID (in this example, myID
contains the ID value and is passed as a parameter):
MATCH (n) WHERE ID(n) = $myId
...
If the node could be deleted before you search for it by native ID, then this technique is not safe, since neo4j can re-assign the native ID of a deleted node to another newly- created node.