Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apoc Trigger in "Phase: After" Never Ends #99

Open
neo-technology-build-agent opened this issue Sep 1, 2022 · 5 comments
Open

Apoc Trigger in "Phase: After" Never Ends #99

neo-technology-build-agent opened this issue Sep 1, 2022 · 5 comments

Comments

@neo-technology-build-agent
Copy link
Collaborator

Issue by leandrogalrinho
Thursday Mar 19, 2020 at 16:10 GMT
Originally opened as neo4j-contrib/neo4j-apoc-procedures#1453


Hello,
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. However, if the trigger is in "phase: before" it all goes as expected.

Expected Behavior

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

Actual Behavior

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

How to Reproduce the Problem

Simple Dataset

CREATE (:TEST {name:'x', _executed:0});
CREATE (:TEST {name:'y', _executed:0});
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'});

Steps

  1. Insert dataset and trigger into neo4j.
  2. Perform this simple query that updates the _executed property of node x, activating the trigger:
MATCH (a:TEST)
WHERE a.name = 'x'
SET a._executed = a._executed+1

Specifications (Mandatory)

Currently used versions

Versions

  • OS: Windows 8.1
  • Neo4j: 3.5.14 Enterprise
  • Neo4j-Apoc: 3.5.0.9
@neo-technology-build-agent
Copy link
Collaborator Author

Comment by hikemachado
Tuesday May 05, 2020 at 18:35 GMT


I`m facing similar issue.
I have a trigger for create relationship, in this trigger I need to create another relationship (but different relationship type) for the node.
every time it is triggered for the specific relationshiptype it never ends

trigger definition:

CALL apoc.trigger.add("Cluster_TRG", 
'UNWIND [rel in {createdRelationships} WHERE type(rel) = "IN_CLUSTER"] AS r with r, startNode(r) as nn, endNode(r) as cn match (cn)<-[]-(b) where id(b) <> id(nn)  with nn, b  match (b)-[outR:Depends_On]->(p) with nn, b,  outR, p create (nn)-[nr:Depends_On]->(p) with p call apoc.log.info("Triggert called " + p.Name) return null',
{phase:'after'})

Versions

  • OS : Windows 10
  • Neo4j : 3.5.5 Community
  • Neo4j-Apoc: 3.5.0-11

@neo-technology-build-agent
Copy link
Collaborator Author

Comment by saibhaskerraju
Monday Jun 22, 2020 at 13:36 GMT


Hi All,
Sincere apologies if this doesn't make sense
I created the below trigger

CALL apoc.trigger.add('increase_followings_and_followers',
'UNWIND $createdRelationships AS rel 
WITH rel, STARTNODE(rel) as follower, ENDNODE(rel) AS followed WITH rel, follower, followed
WHERE TYPE(rel)="HAS_E"
SET follower.followings = 1, followed.followers= 2',
{phase:'before'})

and this is the basic query I am writing

match(p:Post{id:1}) create(c:Comment{id:354}) merge(c)-[:HAS_E]->(p)

I have two scenarios
CASE 1: The Phase in trigger = ' after'
I see new :comment node getting created and attached to :Post node but the query doesn't stop. it keeps on looping
CASE 2: Phase in trigger = ' before '
I don't see new :Comment node not relationship to :Post but query doesn't stop. it keeps on looping

I am running version 4.0.6 and apoc 4.0.0.15

Can someone please let me know what I am missing here.

@neo-technology-build-agent
Copy link
Collaborator Author

Comment by jexp
Tuesday Aug 04, 2020 at 22:51 GMT


@conker84 could you have a look at this?

@neo-technology-build-agent
Copy link
Collaborator Author

Comment by magaton
Monday Jun 07, 2021 at 13:20 GMT


I have exactly the same problem.
Neo4j 4.2.4, apoc, 4.2.0.4
When I run cypher within trigger, all is good, the same applies when trigger is set with phase:'before', but it never completes with phase: 'after'.

@neo-technology-build-agent
Copy link
Collaborator Author

Comment by vga91
Wednesday Jun 30, 2021 at 07:34 GMT


@leandrogalrinho
With the latest Apoc version there is a phase: "afterAsync" to prevent some Transaction errors like this.
Please, could you try with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant