I have just started playing with the new neo4j driver for python and got totally stuck with transactions. How do I check if a transaction completed successfully? As far as I can say commit
function does not automatically raise any errors, i.e. if for instance I provide it with an incorrect Cypher query I get no information on this.
I tried reading the last_result
argument from the Session
object and came up with sth like:
import neo4j.v1 as neo
def db_confirm_transaction_success(session):
try:
w = list(session.last_result)
return True
except neo.CypherError as e:
session.last_result._consumed = True
return False
except neo.ResultError as e:
session.last_result._consumed = True
return False
It kind a works... Yet, it does require modifying private attributes and simply do not seem right/correct. There must be a simpler and more elegant solution.
Thank you in advance for help.
Edit: Just to make it clear Transaction.success
attribute indicates if a transaction should get committed or rolled back. Yet, e.g. Cypher errors can be identified as late as of the queries' execution time.