question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Errors propagate to other queries in the same session

See original GitHub issue

If 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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
swayam18commented, Feb 21, 2018

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.

0reactions
zhenlineocommented, Dec 10, 2018

We’ve improved readme and also API docs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: User Session Query Language - Sessions with Errors
As I see in the API docs in the model for the UserSession there is an errors object, but I can't see how...
Read more >
Refresh error when combining multiple Web queries
We are receiving the following error when Power Bi Service tries to refresh our dataset with the query below. [Unable to combine data]...
Read more >
Full Stack Error Handling with GraphQL and Apollo
Request Errors occur when the client is at fault. There are 3 phases to a GraphQL query and client-caused errors may occur in...
Read more >
Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >
MySQL HeatWave User Guide :: 2.13 Troubleshooting
Solution: This error can occur when querying a report table from a different session. Query the report table using the same session that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found