Apoc Trigger in "Phase: After" never Ends

Hi all! I've ran into an unexpected behavior and can't figure out what's the source of it. I'm using apoc 3.5.0.9, and I'm trying to have a trigger in "phase: after" that creates a relationship with the node that has been updated with some other node, but this causes the trigger to never end.

For instance, with this dataset:

CREATE (:TEST {name:'x', _executed:0});
CREATE (:TEST {name:'y', _executed:0});

And this simple trigger:

CALL apoc.trigger.add('triggerTest','UNWIND apoc.trigger.propertiesByKey({assignedNodeProperties},"_executed") as prop
	WITH prop.node as n
	CREATE (z:SON {father:id(n)})
	CREATE (n)-[:GENERATED]->(z)
	',
{phase:'after'});

Which is supposed to catch the update event and, after the transaction that updates the _executed property commits, creates a new relationship with the updated node and the new node z.

However, unless I terminate the query this never seems to end, and if I do terminate it, it will leave the graph in the same state it was before the update, except that the _executed property was indeed updated... But neither the new node or the new relation was created.

If this said trigger is in "phase: before" or if there are no new relations created in the trigger concerning the node updated (i.e. if there is no relation created using the node n), this has the expected behavior and all goes smoothly...

Can anyone help me understand what's causing this in "phase: after"?

Hi @l.galrinho,

after -- Fire the trigger even first then after make the change on this trigger event
before -- If there trigger requirement satisfies then update the post event first and then to the trigger event .. For and example ```
CALL apoc.trigger.add('updateLabels',"UNWIND apoc.trigger.nodesByLabel({removedLabels},'Actor') AS node
MATCH (n:Actor)
REMOVE n:Actor SET n:Person SET node:Person", {phase:'before'})

I did not understand what do you mean by terminate the query?

Hello @intouch_vivek, and thanks for the quick reply.

What I meant to say with "terminate the query" is that if I try to do a simple query to update the _executed property of a node, for instance:

MATCH (a:TEST)
WHERE a.name = 'x'
SET a._executed = a._executed+1

This query will never end and the circular spinner showed on the neo4j Desktop app will not disappear unless I forcefully cancel this query.

As I said, the trigger I showed works as intended in "phase: before", but I need it to be in "phase: after", and if the trigger creates a relation with the updated node, for instance, in the trigger the node updated is the node n, and if I create a relationship using this node, e.g. (n)-[:RelationName]->(n), when I update the _executed property using the query I posted above, it will never end. And I can't understand why this happens...

@l.galrinho,

Sorry to say, but even i am facing the same issue .

1 Like