@@ -165,17 +165,31 @@ def vm_and_miq_template_ancestry_save_block
165
165
166
166
# Fetch IDs of all vms and genealogy_parents, only if genealogy_parent is present
167
167
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
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
+
173
+ if genealogy_parent_id == x . id
174
+ _log . warn ( "Cannot assign genealogy_parent to same object, ID [#{ x . id } ]" )
175
+ next
171
176
end
177
+
178
+ obj [ x . id ] = genealogy_parent_id
172
179
end
173
180
174
181
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
182
+ next if x . data [ :genealogy_parent ] . nil?
183
+
184
+ genealogy_parent_id = x . data [ :genealogy_parent ] . load . try ( :id )
185
+ next if genealogy_parent_id . nil?
186
+
187
+ if genealogy_parent_id == x . id
188
+ _log . warn ( "Cannot assign genealogy_parent to same object, ID [#{ x . id } ]" )
189
+ next
178
190
end
191
+
192
+ obj [ x . id ] = genealogy_parent_id
179
193
end
180
194
181
195
ActiveRecord ::Base . transaction do
0 commit comments