diff --git a/app/models/manager_refresh/inventory_collection.rb b/app/models/manager_refresh/inventory_collection.rb index e89ee483b15..d8ee4e8117a 100644 --- a/app/models/manager_refresh/inventory_collection.rb +++ b/app/models/manager_refresh/inventory_collection.rb @@ -423,7 +423,7 @@ def initialize(model_class: nil, manager_ref: nil, association: nil, parent: nil @custom_save_block = custom_save_block @custom_reconnect_block = custom_reconnect_block @check_changed = check_changed.nil? ? true : check_changed - @internal_attributes = [:__feedback_edge_set_parent] + @internal_attributes = [:__feedback_edge_set_parent, :__parent_inventory_collections] @complete = complete.nil? ? true : complete @update_only = update_only.nil? ? false : update_only @builder_params = builder_params diff --git a/app/models/manager_refresh/inventory_collection/scanner.rb b/app/models/manager_refresh/inventory_collection/scanner.rb index a937fc2020f..66672a3ee0b 100644 --- a/app/models/manager_refresh/inventory_collection/scanner.rb +++ b/app/models/manager_refresh/inventory_collection/scanner.rb @@ -66,12 +66,17 @@ def scan! end # Transform :parent_inventory_collections symbols to InventoryCollection objects - if targeted? && parent_inventory_collections.present? + if parent_inventory_collections.present? self.parent_inventory_collections = parent_inventory_collections.map do |inventory_collection_index| ic = indexed_inventory_collections[inventory_collection_index] - raise "Can't find InventoryCollection #{inventory_collection_index} from #{inventory_collection}" unless ic - ic - end + if ic.nil? + raise "Can't find InventoryCollection #{inventory_collection_index} from #{inventory_collection}" if targeted? + else + # Add parent_inventory_collection as a dependency, so e.g. disconnect is done in a right order + (dependency_attributes[:__parent_inventory_collections] ||= Set.new) << ic + ic + end + end.compact end # Mark InventoryCollection as finalized aka. scanned diff --git a/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb b/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb index 8a134848e5d..e09df1e10ab 100644 --- a/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb +++ b/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb @@ -331,7 +331,8 @@ :attributes_whitelist => [:raw_power_state, :ext_management_system] ) - expect(inventory_collection.attributes_whitelist).to match_array([:__feedback_edge_set_parent, :ems_ref, + expect(inventory_collection.attributes_whitelist).to match_array([:__feedback_edge_set_parent, + :__parent_inventory_collections, :ems_ref, :name, :location, :raw_power_state, :ext_management_system]) end @@ -358,7 +359,8 @@ :attributes_whitelist => [:raw_power_state, :ext_management_system] ) - expect(inventory_collection.attributes_whitelist).to match_array([:__feedback_edge_set_parent, :uid_ems, + expect(inventory_collection.attributes_whitelist).to match_array([:__feedback_edge_set_parent, + :__parent_inventory_collections, :uid_ems, :name, :location, :raw_power_state, :ext_management_system]) end