[BUG] Errors propagate to other queries in the same session
See original GitHub issueIf a query results in an error (such as a Constraint Violation exception), every future query in the same session also returns the initial error regardless of the correctness of the future query.
I have written a sample script that replicates this behaviour. The database has a unique constraint on pk
. In this script, I create two users but ‘accidentally’ insert the first user twice. The insertion of the first user blows up as expected. However, if I try to add the second user in the same session, I get another constraint violation exception, even though no constraint is actually violated.
Here is the script:
const neo4j = require('neo4j-driver').v1;
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', 'neo4j'));
const session = driver.session();
// UNIQUE CONSTRAINT on user.pk
session.run("CREATE (a:User {pk: 1 })", {}); // PASSES
session.run("CREATE (a:User {pk: 1 })", {}); // FAILS
session.run("CREATE (a:User {pk: 2 })") // SHOULD PASS BUT FAILS!
.subscribe({
onError: function (error) {
console.log(error);
}
});
This is the error that is caught by console log:
{ Neo4jError: Node(39574) already exists with label `User` and property `pk` = 1
...
code: 'Neo.ClientError.Schema.ConstraintValidationFailed',
name: 'Neo4jError' }
Initally, I thought this is a feature, not a bug. But, If I try to insert the user after a delay of a few seconds, it seems to work:
// UNIQUE CONSTRAINT on user.pk
session.run("CREATE (a:User {pk: 1 })", {}); // PASSES
session.run("CREATE (a:User {pk: 1 })", {}); // FAILS
setTimeout(function() {
session.run("CREATE (a:User {pk: 2 })") // PASSES!
.subscribe({
onCompleted: function () {
console.log('INSERTED!');
},
});
}, 1000);
Does anyone know what’s going on? Am I missing something obvious?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Thanks, @lutovich. I wonder if we should call this out in the documentation somewhere. The fact that a single session should only have one query running at any given time and one should create multiple sessions if they want to run parallel queries. It wasn’t super obvious to me.
We’ve improved readme and also API docs.