Skip to content

Commit

Permalink
Make sure _retryable is called before aborting.
Browse files Browse the repository at this point in the history
Since manager._retryable rely on manager.get()._resources to not be
empty, which is cleared after abort() is called. Unless these two lines
are reversed, data manager's should_retry won't get called at all.
  • Loading branch information
sirn committed Jan 21, 2013
1 parent 228ff03 commit 8633062
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyramid_tm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def tm_tween(request):
except:
exc_info = sys.exc_info()
try:
manager.abort()
retryable = manager._retryable(*exc_info[:-1])
manager.abort()
if (number <= 0) or (not retryable):
reraise(*exc_info)
finally:
Expand Down
10 changes: 7 additions & 3 deletions pyramid_tm/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def setUp(self):
self.request = DummyRequest()
self.response = DummyResponse()
self.registry = DummyRegistry()

def _callFUT(self, handler=None, registry=None, request=None, txn=None):
if handler is None:
def handler(request):
Expand Down Expand Up @@ -114,7 +114,7 @@ class Conflict(TransientError):
def handler(request, count=count):
raise Conflict
self.assertRaises(Conflict, self._callFUT, handler=handler)

def test_handler_isdoomed(self):
txn = DummyTransaction(True)
self._callFUT(txn=txn)
Expand Down Expand Up @@ -236,13 +236,15 @@ def __init__(self, doomed=False, retryable=False):
self.committed = 0
self.aborted = 0
self.retryable = retryable
self.active = False

@property
def manager(self):
return self

def _retryable(self, t, v):
return self.retryable
if self.active:
return self.retryable

def get(self):
return self
Expand All @@ -255,12 +257,14 @@ def isDoomed(self):

def begin(self):
self.began+=1
self.active = True
return self

def commit(self):
self.committed+=1

def abort(self):
self.active = False
self.aborted+=1

def note(self, value):
Expand Down

0 comments on commit 8633062

Please sign in to comment.