def get_trace_db_by_live_action(liveaction):
 trace_db = None
 created = False
 trace_context = liveaction.context.get(TRACE_CONTEXT, None)
 if trace_context:
  trace_context = _get_valid_trace_context(trace_context)
  trace_db = get_trace(trace_context=trace_context, ignore_trace_tag=True)
  if (not trace_db):
   trace_db = TraceDB(trace_tag=trace_context.trace_tag)
   created = True
  return (created, trace_db)
 parent_context = executions.get_parent_context(liveaction_db=liveaction)
 if ((not trace_context) and parent_context):
  parent_execution_id = parent_context.get('execution_id', None)
  if parent_execution_id:
   trace_db = get_trace_db_by_action_execution(action_execution_id=parent_execution_id)
   if (not trace_db):
    raise StackStormDBObjectNotFoundError(('No trace found for execution %s' % parent_execution_id))
   return (created, trace_db)
 execution = ActionExecution.get(liveaction__id=str(liveaction.id))
 if execution:
  trace_db = get_trace_db_by_action_execution(action_execution=execution)
 if (not trace_db):
  trace_db = TraceDB(trace_tag=('execution-%s' % str(liveaction.id)))
  created = True
 return (created, trace_db)

def get_trace_db_by_live_action ( liveaction ) : trace_db = None created = False trace_context = liveaction . context . get ( TRACE_CONTEXT , None ) if trace_context : trace_context = _get_valid_trace_context ( trace_context ) trace_db = get_trace ( trace_context = trace_context , ignore_trace_tag = True ) if ( not trace_db ) : trace_db = TraceDB ( trace_tag = trace_context . trace_tag ) created = True return ( created , trace_db ) parent_context = executions . get_parent_context ( liveaction_db = liveaction ) if ( ( not trace_context ) and parent_context ) : parent_execution_id = parent_context . get ( 'execution_id' , None ) if parent_execution_id : trace_db = get_trace_db_by_action_execution ( action_execution_id = parent_execution_id ) if ( not trace_db ) : raise StackStormDBObjectNotFoundError ( ( 'No trace found for execution %s' % parent_execution_id ) ) return ( created , trace_db ) execution = ActionExecution . get ( liveaction__id = str ( liveaction . id ) ) if execution : trace_db = get_trace_db_by_action_execution ( action_execution = execution ) if ( not trace_db ) : trace_db = TraceDB ( trace_tag = ( 'execution-%s' % str ( liveaction . id ) ) ) created = True return ( created , trace_db )
given a liveaction does the best attempt to return a tracedb .