Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 5.0/5.1 Use o.reload.assoc, assoc(true) is gone #18079

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/service_template_ansible_tower.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ServiceTemplateAnsibleTower < ServiceTemplate
include ServiceConfigurationMixin

before_save :remove_invalid_resource
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

before_update :remove_invalid_resource

alias job_template configuration_script
alias job_template= configuration_script=
Expand All @@ -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) }
Copy link
Member Author

@jrafanie jrafanie Oct 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei Can you review this change? I needed to remove the .resource(true) to force reload of the association because .resource doesn't accept any parameters in rails 5.1. The alternative of .reload.resource causes issues because this before_save is called before creates and updates and blows up on creates because it's not yet persisted. I changed this to a before_update, to simplify the code based on the comment you added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the s/\](true\)/reload

curious:

Do we want to change from delete_if to each? think the to_a negates any real side effects.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think this needs to be cleanedup and possibly moved up as you suggested elsewhere. I'm not sure why we need to delete_if on an array we don't retain but that seems besides the point of the PR. I agree, it's needs further refinement.

service_resources.to_a.delete_if { |r| r.destroy unless r.reload.resource.present? }
end

def create_subtasks(_parent_service_task, _parent_service)
Expand Down