Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-28-2020 04:28 PM
After I added after
trigger some of my subsequent queries just freeze and lock me, so I can not do any other CREATE
. MATCH
to see existing nodes just works fine and are successfuly created. I use Neo4j in version 3.5.16 enterprise
My trigger:
CALL apoc.trigger.add(
'location_node_after',
'UNWIND {createdNodes} AS node WITH node WHERE node:Location MATCH (target :Location) WHERE target.pk <> node.pk CREATE (node)-[r: PATH_TO { distance: distance(point({ latitude: target.lat, longitude: target.lon }), point({ latitude: node.lat, longitude: node.lon })) }]->(target)',
{ phase: 'after' }
);
Query to try out:
CREATE
(random :Location { pk: 1, name: 'random', lat: 50.082010, lon: 14.418595 }),
(random2 :Location { pk: 2, name: 'random2', lat: 49.742635, lon: 14.717182 }),
(media1 :Media { pk: 1, taken_at: 1 }),
(person1 :Person { pk: 1, gender: 'female' })
WITH random, media1, person1
CREATE (person1)-[:TOOK_PHOTO]->(media1)-[:PHOTO_IN]->(random); // this will freeze
But this query works (it will create desired relation):
CREATE (:Location { pk: 1, name: "a", lat: 50.061512, lon: 14.604215});
CREATE (:Location { pk: 2, name: "b", lat: 50.063950, lon: 14.604086});
After I try to see running queries via apoc
there is nothing active. When I try {assignedLabels}
instead of createdNodes
it behaves the same.
Thanks for helping me.
Solved! Go to Solution.
03-30-2020 07:42 AM
The after tigger code es executed in a separate transaction and it's itself subject to the after trigger, which is executed in a separate transaction, .....
You should actually see the new created nodes in the before phase.
In graph changes by triggers are normally done in before
phase. after
is used for post actions like writing to a log file or pushing some information about the change to another system.
03-30-2020 12:57 AM
Have you tried to use phase:before
instead? If you're using after it's done in a separate transaction that is subject to triggers as well, opening a recursive box of pandora.
03-30-2020 05:25 AM
I need to use AFTER trigger, becuase I need to work with newly created nodes. What's wrong with AFTER triggers? I just don't get it why it doesn't work - inside trigger I did not create any new nodes, thus no recursion should happen, shouldn't it?
03-30-2020 07:42 AM
The after tigger code es executed in a separate transaction and it's itself subject to the after trigger, which is executed in a separate transaction, .....
You should actually see the new created nodes in the before phase.
In graph changes by triggers are normally done in before
phase. after
is used for post actions like writing to a log file or pushing some information about the change to another system.
06-22-2022 08:56 PM - edited 06-22-2022 08:57 PM
Hi @stefan_armbrust
is it the problem with create triggers only or others as well?
I had tried to run the below trigger which is basically a trigger for update event and I had the same problem.
the trigger:
When I used the phase as 'before' it worked fine but incase of phase as 'after' the queries never got terminated.
what could be the problem here?
06-22-2022 08:59 PM
In which case 'after' phase can be used and in which case it can't be?
03-30-2020 12:52 PM
Thanks, making it as BEFORE seems to work now!
All the sessions of the conference are now available online