Skip to content

Commit

Permalink
fixes #1556: request trigger not be saved if syntactically incorrect (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
conker84 authored Jul 20, 2020
1 parent e5c66aa commit 7320ffb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/apoc/periodic/Periodic.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public Stream<JobInfo> repeat(@Name("name") String name, @Name("statement") Stri
}

private void validateQuery(String statement) {
db.executeTransactionally("EXPLAIN " + statement);
Util.validateQuery(db, statement);
}

@Procedure(mode = Mode.WRITE)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/apoc/trigger/Trigger.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package apoc.trigger;

import apoc.coll.SetBackedList;
import apoc.util.Util;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
Expand Down Expand Up @@ -91,6 +92,7 @@ public List<Map<String,Object>> propertiesByKey(@Name("propertyEntries") Map<Str
@Procedure(mode = Mode.WRITE)
@Description("add a trigger kernelTransaction under a name, in the kernelTransaction you can use {createdNodes}, {deletedNodes} etc., the selector is {phase:'before/after/rollback'} returns previous and new trigger information. Takes in an optional configuration.")
public Stream<TriggerInfo> add(@Name("name") String name, @Name("kernelTransaction") String statement, @Name(value = "selector"/*, defaultValue = "{}"*/) Map<String,Object> selector, @Name(value = "config", defaultValue = "{}") Map<String,Object> config) {
Util.validateQuery(db, statement);
Map<String,Object> params = (Map)config.getOrDefault("params", Collections.emptyMap());
Map<String, Object> removed = triggerHandler.add(name, statement, selector, params);
if (removed != null) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/apoc/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -896,4 +896,8 @@ public static <T> Set<T> intersection(Collection<T> a, Collection<T> b) {
intersection.retainAll(b);
return intersection;
}

public static void validateQuery(GraphDatabaseService db, String statement) {
db.executeTransactionally("EXPLAIN " + statement);
}
}
6 changes: 5 additions & 1 deletion src/test/java/apoc/trigger/TriggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.Test;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.QueryExecutionException;
import org.neo4j.test.rule.DbmsRule;
import org.neo4j.test.rule.ImpermanentDbmsRule;

Expand Down Expand Up @@ -219,6 +220,9 @@ public void testTriggerResume() throws Exception {
});
}


@Test(expected = QueryExecutionException.class)
public void showThrowAnException() throws Exception {
db.executeTransactionally("CALL apoc.trigger.add('test','UNWIND $createdNodes AS n SET n.txId = , n.txTime = $commitTime',{})");
}

}

0 comments on commit 7320ffb

Please sign in to comment.