Skip to content

Commit

Permalink
Prevent a vm or template being its own parent
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Jan 10, 2025
1 parent a2a7b2d commit 5938445
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,23 @@ def vm_and_miq_template_ancestry_save_block

# Fetch IDs of all vms and genealogy_parents, only if genealogy_parent is present
vms_genealogy_parents = vms_inventory_collection.data.each_with_object({}) do |x, obj|
unless x.data[:genealogy_parent].nil?
genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
obj[x.id] = genealogy_parent_id if genealogy_parent_id
end
next if x.data[:genealogy_parent].nil?

genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
next if genealogy_parent_id.nil?
next if genealogy_parent_id == x.id

obj[x.id] = genealogy_parent_id
end

miq_template_genealogy_parents = miq_templates_inventory_collection.data.each_with_object({}) do |x, obj|
unless x.data[:genealogy_parent].nil?
genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
obj[x.id] = genealogy_parent_id if genealogy_parent_id
end
next if x.data[:genealogy_parent].nil?

genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
next if genealogy_parent_id.nil?
next if genealogy_parent_id == x.id

obj[x.id] = genealogy_parent_id
end

ActiveRecord::Base.transaction do
Expand Down

0 comments on commit 5938445

Please sign in to comment.