def retry_if_session_inactive(context_var_name='context'):
 def decorator(f):
  try:
   ctx_arg_index = p_util.getargspec(f).args.index(context_var_name)
  except ValueError:
   raise RuntimeError((_LE('Could not find position of var %s') % context_var_name))
  f_with_retry = retry_db_errors(f)
  @six.wraps(f)
  def wrapped(*args, **kwargs):
   if (context_var_name in kwargs):
    context = kwargs[context_var_name]
   else:
    context = args[ctx_arg_index]
   method = (f if context.session.is_active else f_with_retry)
   return method(*args, **kwargs)
  return wrapped
 return decorator

def retry_if_session_inactive ( context_var_name = 'context' ) : def decorator ( f ) : try : ctx_arg_index = p_util . getargspec ( f ) . args . index ( context_var_name ) except ValueError : raise RuntimeError ( ( _LE ( 'Could not find position of var %s' ) % context_var_name ) ) f_with_retry = retry_db_errors ( f ) @ six . wraps ( f ) def wrapped ( * args , ** kwargs ) : if ( context_var_name in kwargs ) : context = kwargs [ context_var_name ] else : context = args [ ctx_arg_index ] method = ( f if context . session . is_active else f_with_retry ) return method ( * args , ** kwargs ) return wrapped return decorator
retries only if the session in the context is inactive .