Skip to content

Commit 5938445

Browse files
committed
Prevent a vm or template being its own parent
1 parent a2a7b2d commit 5938445

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

app/models/manageiq/providers/inventory/persister/builder/cloud_manager.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,23 @@ def vm_and_miq_template_ancestry_save_block
165165

166166
# Fetch IDs of all vms and genealogy_parents, only if genealogy_parent is present
167167
vms_genealogy_parents = vms_inventory_collection.data.each_with_object({}) do |x, obj|
168-
unless x.data[:genealogy_parent].nil?
169-
genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
170-
obj[x.id] = genealogy_parent_id if genealogy_parent_id
171-
end
168+
next if x.data[:genealogy_parent].nil?
169+
170+
genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
171+
next if genealogy_parent_id.nil?
172+
next if genealogy_parent_id == x.id
173+
174+
obj[x.id] = genealogy_parent_id
172175
end
173176

174177
miq_template_genealogy_parents = miq_templates_inventory_collection.data.each_with_object({}) do |x, obj|
175-
unless x.data[:genealogy_parent].nil?
176-
genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
177-
obj[x.id] = genealogy_parent_id if genealogy_parent_id
178-
end
178+
next if x.data[:genealogy_parent].nil?
179+
180+
genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
181+
next if genealogy_parent_id.nil?
182+
next if genealogy_parent_id == x.id
183+
184+
obj[x.id] = genealogy_parent_id
179185
end
180186

181187
ActiveRecord::Base.transaction do

0 commit comments

Comments
 (0)