@@ -300,24 +300,34 @@ def get(self, ci_id):
300300
301301 relations = {"parents" : [], "children" : []}
302302 try :
303- from api .lib .cmdb .ci import CIRelationManager
304303 children = CIRelationManager .get_children (ci_id , ret_key = RetKey .NAME )
305304 for type_name , cis in children .items ():
305+ child_type = CITypeCache .get (type_name ) if type_name else None
306+ child_type_name = child_type .alias if child_type else (type_name or "" )
306307 for c in cis :
307- c ["_type_name" ] = CITypeCache . get ( type_name ). alias if type_name else type_name
308+ c ["_type_name" ] = child_type_name
308309 relations ["children" ].append (c )
310+ except Exception as e :
311+ current_app .logger .exception ("failed to load child relations for ci_id=%s: %s" , ci_id , e )
309312
310- parent_ids = CIRelationManager .get_parent_ids ([ci_id ])
311- if ci_id in parent_ids :
312- for p_id , p_type_id in parent_ids [ci_id ]:
313- parent_ci = CIManager .get_cis_by_ids ([str (p_id )], ret_key = RetKey .NAME )
314- if parent_ci :
315- for p in parent_ci :
316- p_type = CITypeCache .get (p_type_id ) if p_type_id else None
317- p ["_type_name" ] = p_type .alias if p_type else ""
318- relations ["parents" ].append (p )
319- except Exception :
320- pass
313+ try :
314+ parent_ids = CIRelationManager .get_parent_ids ([ci_id ]) or {}
315+ for p_id , p_type_id in parent_ids .get (ci_id , []):
316+ try :
317+ parent_ci = CIManager .get_cis_by_ids ([str (p_id )], ret_key = RetKey .NAME ) or []
318+ except Exception as e :
319+ current_app .logger .exception (
320+ "failed to load parent ci for ci_id=%s parent_id=%s: %s" , ci_id , p_id , e
321+ )
322+ continue
323+
324+ p_type = CITypeCache .get (p_type_id ) if p_type_id else None
325+ parent_type_name = p_type .alias if p_type else ""
326+ for p in parent_ci :
327+ p ["_type_name" ] = parent_type_name
328+ relations ["parents" ].append (p )
329+ except Exception as e :
330+ current_app .logger .exception ("failed to load parent relations for ci_id=%s: %s" , ci_id , e )
321331
322332 from api .lib .cmdb .history import AttributeHistoryManger
323333 try :
0 commit comments