diff --git a/neo4j/v1/api.py b/neo4j/v1/api.py index 306c534ab..2f4b693c0 100644 --- a/neo4j/v1/api.py +++ b/neo4j/v1/api.py @@ -27,7 +27,7 @@ from neo4j.bolt import ProtocolError, ServiceUnavailable from neo4j.compat import urlparse -from neo4j.exceptions import CypherError +from neo4j.exceptions import CypherError, TransientError from .exceptions import DriverError, SessionError, SessionExpired, TransactionError @@ -435,6 +435,11 @@ def _run_transaction(self, access_mode, unit_of_work, *args, **kwargs): return unit_of_work(tx, *args, **kwargs) except (ServiceUnavailable, SessionExpired) as error: last_error = error + except TransientError as error: + if is_retriable_transientError(error): + last_error = error + else: + raise error sleep(next(retry_delay)) t1 = clock() raise last_error @@ -461,6 +466,17 @@ def __bookmark__(self, result): pass +def is_retriable_transientError(error): + """ + :type error: TransientError + """ + if (error.code.lower() != "neo.transienterror.transaction.terminated" + and error.code.lower() != "neo.transienterror.transaction.lockclientstopped"): + return True + else: + return False + + class Transaction(object): """ Container for multiple Cypher queries to be executed within a single context. Transactions can be used within a :py:const:`with`