cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Neo4j Transaction Summary?

laxmimerit
Node Link

Hi,
I am trying to get a transaction summary after a read or write transaction using neo4j python-driver. I have written some code to get this but these aren't working.

Code

def write_data(tx, query):
    result = tx.run(query)
    record = result.single()
    value = record.value()
    info = result.consume()
    return value, info

def commit_data(query):
    with driver.session(database="neo4j") as session:
        node_id, info = session.write_transaction(write_data,query)
        print(node_id, info, type(node_id), info.database, info.plan, info.profile)
output
--------
1 <neo4j.work.summary.ResultSummary object at 0x000001DB94F1D0D0> <class 'int'> neo4j None None

I get the type of result as ResultSummary but this object doesn't have any useful info here. This summary clearly says result plan and profile both are None but actually result should be having information like this as per neo4j desktop browser. Kindly help me to get the result summary.

[
  {
    "batches": 1,
    "total": 8077,
    "timeTaken": 0,
    "committedOperations": 8077,
    "failedOperations": 0,
    "failedBatches": 0,
    "retries": 0,
    "errorMessages": {

    },
    "batch": {
"total": 1,
"committed": 1,
"failed": 0,
"errors": {

      }
    },
    "operations": {
"total": 8077,
"committed": 8077,
"failed": 0,
"errors": {

      }
    },
    "wasTerminated": false,
    "failedParams": {

    },
    "updateStatistics": {
"nodesDeleted": 8077,
"labelsAdded": 0,
"relationshipsCreated": 0,
"nodesCreated": 0,
"propertiesSet": 0,
"relationshipsDeleted": 14528,
"labelsRemoved": 0
    }
  }
]
1 ACCEPTED SOLUTION

laxmimerit
Node Link

Just wanted to post an answer to this question. Use following code to get the txn details.

def commit_data(query):
    with driver.session(database="neo4j") as session:
        tx = session.begin_transaction()
        result = tx.run(query)
        result = [dict(i) for i in result]
        
       # uncomment below line to see the complete txn summary.
        # print(result) 

        if result[0]['failedOperations']>0:
            print(query)
            print(result)
            raise 'Error! Please recheck your query.'
        
        tx.commit()

Hope it will help others.

View solution in original post

2 REPLIES 2

david_allen
Neo4j
Neo4j

Hey, have a look at the API documentation here:

https://neo4j.com/docs/api/python-driver/current/api.html#resultsummary

The thing that you're looking for is in the counters element underneath of the resultsummary. Make sure to check the linked API documentation to see how the SummaryCounters object is laid out

https://neo4j.com/docs/api/python-driver/current/api.html#summarycounters

laxmimerit
Node Link

Just wanted to post an answer to this question. Use following code to get the txn details.

def commit_data(query):
    with driver.session(database="neo4j") as session:
        tx = session.begin_transaction()
        result = tx.run(query)
        result = [dict(i) for i in result]
        
       # uncomment below line to see the complete txn summary.
        # print(result) 

        if result[0]['failedOperations']>0:
            print(query)
            print(result)
            raise 'Error! Please recheck your query.'
        
        tx.commit()

Hope it will help others.