Created
August 31, 2020 19:07
-
-
Save kristof-mattei/518c23e6e7610f1dc89e835a82dc853a to your computer and use it in GitHub Desktop.
Neo4j tx.run swallows errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from neo4j import GraphDatabase | |
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "****")) | |
query = """WITH {} AS x | |
CALL apoc.util.validate(x IS NOT NULL, 'A query that fails', [x]) | |
RETURN false""" | |
def read_transaction(): | |
def _callback(tx): | |
return tx.run(query) | |
with driver.session() as session: | |
result = session.read_transaction(_callback) | |
return list(result.records()) | |
def read_transaction_deferred(): | |
def _callback(tx): | |
return tx.run(query) | |
with driver.session() as session: | |
result = session.read_transaction(_callback) | |
return result | |
def run(): | |
with driver.session() as session: | |
result = session.run(query) | |
return list(result.records()) | |
def run_deferred(): | |
with driver.session() as session: | |
result = session.run(query) | |
return result | |
def run_test(func, iter): | |
success = False | |
print(f"START: {func.__name__}") | |
try: | |
result = func() | |
for r in iter(result): | |
print(r) | |
success = True | |
except Exception as e: | |
print(e) | |
print(f"ERROR: {func.__name__}") | |
if success: | |
print(f"OK: {func.__name__}") | |
run_test(read_transaction, lambda r: r) | |
run_test(read_transaction_deferred, lambda r: r.records()) | |
run_test(run, lambda r: r) | |
run_test(run_deferred, lambda r: r.records()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment