From 3f4f8c6c00e2e7fa92d74a834f50930d4f93069d Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Thu, 4 Oct 2018 11:42:48 -0400 Subject: [PATCH] Use o.reload.assoc, assoc(true) is gone Note, the before_save was calling remove_invalid_resource on create which didn't make sense because it was trying to find service_resources with orphaned resources, which can't happen unless the service_template itself has been saved. Because of this, it makes sense to change this to before_update instead of adding r.persisted? checks in the remove_invalid_resource method. The force reload parameter was removed from associations in: https://github.com/rails/rails/commit/09cac8c67af It was previously deprecated here: https://github.com/rails/rails/commit/6eae366d0d2e5d5211eeaf955f56bd1dc6836758 From that commit: For collections: @user.posts.reload # Instead of @user.posts(true) For singular associations: @user.reload.profile # Instead of @user.profile(true) Extracted from https://github.com/ManageIQ/manageiq/pull/18076 --- app/models/service_template_ansible_tower.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/service_template_ansible_tower.rb b/app/models/service_template_ansible_tower.rb index 2944a9cf59a..78cf14c81c2 100644 --- a/app/models/service_template_ansible_tower.rb +++ b/app/models/service_template_ansible_tower.rb @@ -1,7 +1,7 @@ class ServiceTemplateAnsibleTower < ServiceTemplate include ServiceConfigurationMixin - before_save :remove_invalid_resource + before_update :remove_invalid_resource alias job_template configuration_script alias job_template= configuration_script= @@ -24,7 +24,7 @@ def self.create_catalog_item(options, _auth_user = nil) def remove_invalid_resource # remove the resource from both memory and table - service_resources.to_a.delete_if { |r| r.destroy unless r.resource(true) } + service_resources.to_a.delete_if { |r| r.destroy unless r.reload.resource.present? } end def create_subtasks(_parent_service_task, _parent_service)