def capture_transaction_exceptions(func):
 def raise_the_exception(conn, exc):
  if ('current transaction is aborted, commands ignored until end of transaction block' in six.text_type(exc)):
   exc_info = getattr(conn, '_last_exception', None)
   if (exc_info is None):
    raise
   new_exc = TransactionAborted(sys.exc_info(), exc_info)
   six.reraise(new_exc.__class__, new_exc, exc_info[2])
  conn._last_exception = sys.exc_info()
  raise
 @wraps(func)
 def inner(self, *args, **kwargs):
  try:
   return func(self, *args, **kwargs)
  except Exception as e:
   raise_the_exception(self.db, e)
 return inner

def capture_transaction_exceptions ( func ) : def raise_the_exception ( conn , exc ) : if ( 'current transaction is aborted, commands ignored until end of transaction block' in six . text_type ( exc ) ) : exc_info = getattr ( conn , '_last_exception' , None ) if ( exc_info is None ) : raise new_exc = TransactionAborted ( sys . exc_info ( ) , exc_info ) six . reraise ( new_exc . __class__ , new_exc , exc_info [ 2 ] ) conn . _last_exception = sys . exc_info ( ) raise @ wraps ( func ) def inner ( self , * args , ** kwargs ) : try : return func ( self , * args , ** kwargs ) except Exception as e : raise_the_exception ( self . db , e ) return inner
catches database errors and reraises them on subsequent errors that throw some cruft about transaction aborted .