def wrap_db_error(f):
 def _wrap(*args, **kwargs):
  try:
   return f(*args, **kwargs)
  except sqlalchemy.exc.OperationalError as e:
   if (not is_db_connection_error(e.args[0])):
    raise
   remaining_attempts = _MAX_RETRIES
   while True:
    LOG.warning(_('SQL connection failed. %d attempts left.'), remaining_attempts)
    remaining_attempts -= 1
    time.sleep(_RETRY_INTERVAL)
    try:
     return f(*args, **kwargs)
    except sqlalchemy.exc.OperationalError as e:
     if ((remaining_attempts == 0) or (not is_db_connection_error(e.args[0]))):
      raise
    except sqlalchemy.exc.DBAPIError:
     raise
  except sqlalchemy.exc.DBAPIError:
   raise
 _wrap.func_name = f.func_name
 return _wrap

def wrap_db_error ( f ) : def _wrap ( * args , ** kwargs ) : try : return f ( * args , ** kwargs ) except sqlalchemy . exc . OperationalError as e : if ( not is_db_connection_error ( e . args [ 0 ] ) ) : raise remaining_attempts = _MAX_RETRIES while True : LOG . warning ( _ ( 'SQL connection failed. %d attempts left.' ) , remaining_attempts ) remaining_attempts -= 1 time . sleep ( _RETRY_INTERVAL ) try : return f ( * args , ** kwargs ) except sqlalchemy . exc . OperationalError as e : if ( ( remaining_attempts == 0 ) or ( not is_db_connection_error ( e . args [ 0 ] ) ) ) : raise except sqlalchemy . exc . DBAPIError : raise except sqlalchemy . exc . DBAPIError : raise _wrap . func_name = f . func_name return _wrap
retry db connection .