@@ -699,6 +699,7 @@ def delete(cls, type_id, attr_ids=None):
699699
700700 for attr_id in attr_ids :
701701 attr = AttributeCache .get (attr_id )
702+ ci_ids_to_cache = set ()
702703
703704 if ci_type .default_order_attr == attr .name or ci_type .default_order_attr == "-{}" .format (attr .name ):
704705 return abort (400 , ErrFormat .cannot_delete_default_order_attr )
@@ -717,13 +718,15 @@ def delete(cls, type_id, attr_ids=None):
717718 if existed is not None :
718719 existed .soft_delete ()
719720
720- for ci in CI . get_by (type_id = type_id , to_dict = False ):
721- AttributeValueManager . delete_attr_value ( attr_id , ci . id , commit = False )
721+ child_ids = CITypeInheritanceManager . recursive_children (type_id )
722+ type_ids_for_cleanup = [ type_id ] + child_ids
722723
723- ci_cache .apply_async (args = (ci .id , None , None ), queue = CMDB_QUEUE )
724+ for _type_id in type_ids_for_cleanup :
725+ for ci in CI .get_by (type_id = _type_id , to_dict = False ):
726+ AttributeValueManager .delete_attr_value (attr_id , ci .id , commit = False )
727+ ci_ids_to_cache .add (ci .id )
724728
725- child_ids = CITypeInheritanceManager .recursive_children (type_id )
726- for _type_id in [type_id ] + child_ids :
729+ for _type_id in type_ids_for_cleanup :
727730 for item in CITypeUniqueConstraint .get_by (type_id = _type_id , to_dict = False ):
728731 if attr_id in item .attr_ids :
729732 attr_ids = copy .deepcopy (item .attr_ids )
@@ -757,6 +760,8 @@ def delete(cls, type_id, attr_ids=None):
757760 db .session .commit ()
758761
759762 CITypeAttributeCache .clean (type_id , attr_id )
763+ for ci_id in ci_ids_to_cache :
764+ ci_cache .apply_async (args = (ci_id , None , None ), queue = CMDB_QUEUE )
760765
761766 if ci_type .show_id == attr_id :
762767 ci_type .update (show_id = None , filter_none = False )
0 commit comments