def transaction_retry(max_retries=1):
 def _outer(fun):
  @wraps(fun)
  def _inner(*args, **kwargs):
   _max_retries = kwargs.pop(u'exception_retry_count', max_retries)
   for retries in count(0):
    try:
     return fun(*args, **kwargs)
    except Exception:
     if (retries >= _max_retries):
      raise
     try:
      rollback_unless_managed()
     except Exception:
      pass
  return _inner
 return _outer

def transaction_retry ( max_retries = 1 ) : def _outer ( fun ) : @ wraps ( fun ) def _inner ( * args , ** kwargs ) : _max_retries = kwargs . pop ( u'exception_retry_count' , max_retries ) for retries in count ( 0 ) : try : return fun ( * args , ** kwargs ) except Exception : if ( retries >= _max_retries ) : raise try : rollback_unless_managed ( ) except Exception : pass return _inner return _outer
decorator for methods doing database operations .