# Apoc Trigger in "Phase: After" never Ends

**URL:** <https://community.neo4j.com/t/apoc-trigger-in-phase-after-never-ends/16030>\
**Category:** Procedures & APOC\
**Tags:** apoc\
**Created:** [March 19, 2020, 3:52pm UTC](https://community.neo4j.com/t/apoc-trigger-in-phase-after-never-ends/16030 "2020-03-19T15:52:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![l.galrinho](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/l.galrinho/32/9920_2.png) [@l.galrinho](https://community.neo4j.com/u/l.galrinho)\
**Post date:** [March 19, 2020, 3:52pm UTC](https://community.neo4j.com/t/apoc-trigger-in-phase-after-never-ends/16030/1 "2020-03-19T15:52:49Z")

</div>

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:

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

```

And this simple trigger:

```auto
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"**?

---

<div class="post-metadata">

**Author:** ![intouch\_vivek](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/intouch_vivek/32/4097_2.png) [@intouch\_vivek](https://community.neo4j.com/u/intouch_vivek)\
**Post date:** [March 19, 2020, 5:43pm UTC](https://community.neo4j.com/t/apoc-trigger-in-phase-after-never-ends/16030/2 "2020-03-19T17:43:11Z")

</div>

> [@l.galrinho](#):
>
> . But n

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?

---

<div class="post-metadata">

**Author:** ![l.galrinho](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/l.galrinho/32/9920_2.png) [@l.galrinho](https://community.neo4j.com/u/l.galrinho)\
**Post date:** [March 20, 2020, 10:36am UTC](https://community.neo4j.com/t/apoc-trigger-in-phase-after-never-ends/16030/3 "2020-03-20T10:36:53Z")

</div>

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:

```auto
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...

---

<div class="post-metadata">

**Author:** ![intouch\_vivek](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/intouch_vivek/32/4097_2.png) [@intouch\_vivek](https://community.neo4j.com/u/intouch_vivek)\
**Post date:** [March 21, 2020, 4:49pm UTC](https://community.neo4j.com/t/apoc-trigger-in-phase-after-never-ends/16030/4 "2020-03-21T16:49:45Z")

</div>

> [@l.galrinho](#):
>
> MATCH (a:TEST) WHERE a.name = 'x' SET a.\_executed = a.\_executed+1

@l.galrinho,

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