This example in the readme is written in a weird way for no apparent reason:
txn = client.txn()
try:
# ...
# Perform any number of queries and mutations
# ...
# and finally...
txn.commit()
except Exception as e:
if isinstance(e, pydgraph.AbortedError):
# Retry or handle exception.
else:
raise e
finally:
# Clean up. Calling this after txn.commit() is a no-op
# and hence safe.
txn.discard()
It would behave exactly the same way but make more sense written like this:
txn = client.txn()
try:
# ...
# Perform any number of queries and mutations
# ...
# and finally...
txn.commit()
except pydgraph.AbortedError:
# Retry or handle exception.
finally:
# Clean up. Calling this after txn.commit() is a no-op
# and hence safe.
txn.discard()