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 20d5280
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions neo4j/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@

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


_warned_about_transaction_bookmarks = False


READ_ACCESS = "READ"
WRITE_ACCESS = "WRITE"

Expand All @@ -53,7 +51,6 @@ def retry_delay_generator(initial_delay, multiplier, jitter_factor):


class ValueSystem(object):

def hydrate(self, values):
""" Hydrate values from raw representations into client objects.
"""
Expand Down Expand Up @@ -435,6 +432,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 +463,17 @@ def __bookmark__(self, result):
pass


def is_retriable_transientError(error):
"""
:type error: TransientError
"""
if (error.code != "Neo.TransientError.Transaction.Terminated"
and error.code != "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 20d5280

Please sign in to comment.