def _to_trace_component_db(component):
 if (not isinstance(component, (basestring, dict))):
  print type(component)
  raise ValueError('Expected component to be str or dict')
 object_id = (component if isinstance(component, basestring) else component['id'])
 ref = (component.get('ref', '') if isinstance(component, dict) else '')
 caused_by = (component.get('caused_by', {}) if isinstance(component, dict) else {})
 return TraceComponentDB(object_id=object_id, ref=ref, caused_by=caused_by)

def _to_trace_component_db ( component ) : if ( not isinstance ( component , ( basestring , dict ) ) ) : print type ( component ) raise ValueError ( 'Expected component to be str or dict' ) object_id = ( component if isinstance ( component , basestring ) else component [ 'id' ] ) ref = ( component . get ( 'ref' , '' ) if isinstance ( component , dict ) else '' ) caused_by = ( component . get ( 'caused_by' , { } ) if isinstance ( component , dict ) else { } ) return TraceComponentDB ( object_id = object_id , ref = ref , caused_by = caused_by )
take the component as string or a dict and will construct a tracecomponentdb .