Skip to content

Commit d96c30e

Browse files
author
Zhen
committed
Support transient but not terminated by user errors in retry
1 parent 20cbad8 commit d96c30e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

neo4j/v1/api.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from neo4j.bolt import ProtocolError, ServiceUnavailable
2929
from neo4j.compat import urlparse
30-
from neo4j.exceptions import CypherError
30+
from neo4j.exceptions import CypherError, TransientError
3131

3232
from .exceptions import DriverError, SessionError, SessionExpired, TransactionError
3333

@@ -435,6 +435,11 @@ def _run_transaction(self, access_mode, unit_of_work, *args, **kwargs):
435435
return unit_of_work(tx, *args, **kwargs)
436436
except (ServiceUnavailable, SessionExpired) as error:
437437
last_error = error
438+
except TransientError as error:
439+
if is_retriable_transientError(error):
440+
last_error = error
441+
else:
442+
raise error
438443
sleep(next(retry_delay))
439444
t1 = clock()
440445
raise last_error
@@ -461,6 +466,17 @@ def __bookmark__(self, result):
461466
pass
462467

463468

469+
def is_retriable_transientError(error):
470+
"""
471+
:type error: TransientError
472+
"""
473+
if (error.code.lower() != "neo.transienterror.transaction.terminated"
474+
and error.code.lower() != "neo.transienterror.transaction.lockclientstopped"):
475+
return True
476+
else:
477+
return False
478+
479+
464480
class Transaction(object):
465481
""" Container for multiple Cypher queries to be executed within
466482
a single context. Transactions can be used within a :py:const:`with`

0 commit comments

Comments
 (0)