Skip to content

Commit

Permalink
Support transient but not terminated by user errors in retry
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhen committed Apr 24, 2017
1 parent 20cbad8 commit d96c30e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion neo4j/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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`
Expand Down

0 comments on commit d96c30e

Please sign in to comment.