-
Notifications
You must be signed in to change notification settings - Fork 897
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
Adds task to subservices for correct retirement completion #17912
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@tinaafitz can you take a look at this please to make sure it's okay before I spend time fixing the tests? |
@tinaafitz can you please take a look? I need to fix the blocker bug that depends on this change. |
@miq-bot remove_label wip |
app/models/service_retire_task.rb
Outdated
@@ -42,6 +41,7 @@ def create_retire_subtasks(parent_service) | |||
# Initial Options[:dialog] to an empty hash so we do not pass down dialog values to child services tasks | |||
nh['options'][:dialog] = {} | |||
new_task = create_task(svc_rsc, parent_service, nh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@d-m-u We need to pass the task(as parent_task) into the create_task method.
Then, we should set the parent_task_id to the parent_task.id here:
:parent_task_id => id, |
And, we should set the parent_task.miq_request_tasks accordingly:
new_task.source = svc_rsc.resource |
parent_task.miq_request_tasks << new_task
2a74486
to
7d6e8c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@d-m-u Please review failing test. |
@@ -41,23 +40,25 @@ def create_retire_subtasks(parent_service) | |||
nh['options'] = options.except(:child_tasks) | |||
# Initial Options[:dialog] to an empty hash so we do not pass down dialog values to child services tasks | |||
nh['options'][:dialog] = {} | |||
new_task = create_task(svc_rsc, parent_service, nh) | |||
new_task = create_task(svc_rsc, parent_service, nh, parent_task) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@d-m-u The nh
has is pulling in virtual columns which is causing the test failure:
Failure/Error: new_task = (svc_rsc.resource.type.demodulize + "RetireTask").constantize.new(nh)
ActiveModel::MissingAttributeError:
can't write unknown attribute `href_slug`
# ./app/models/service_retire_task.rb:53:in `create_task'
# ./app/models/service_retire_task.rb:43:in `block in create_retire_subtasks'
...
You can fix this by excluding the virtual columns on line 39 using self.class.virtual_attribute_names
nh = attributes.except("id", "created_on", "updated_on", "type", "state", "status", "message", *self.class.virtual_attribute_names)
@mkanoor can you please review? |
The test failure addressed by the removal of the virtual attributes (see https://github.com/ManageIQ/manageiq/pull/17912/files#r217853506) is a TODO that needs to be addressed subsequently. It'd be nice to get this merged as is because it's a bug fix. I vote that we address the virtual attribute weirdness later, I'll open an issue for it. Input, @gmcculloug @tinaafitz @Fryguy ?? |
@d-m-u I agree that we should address the virtual attribute issue separately. |
The issue is #17993 |
@miq-bot add_label blocker |
Agreed. Since this is a blocker the suggested work-around to ensure we exclude virtual attributes from the new hash should be good for now. @Fryguy any issue with this work-around while we try to address the deeper active_record bug? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive by comment
(@d-m-u pinged me earlier, so I got a bit nerd sniped...)
app/models/service_retire_task.rb
Outdated
parent_service.service_resources.collect do |svc_rsc| | ||
next unless svc_rsc.resource.try(:retireable?) | ||
# TODO: the next line deals with the filtering for provisioning | ||
# (https://github.com/ManageIQ/manageiq/blob/3921e87915b5a69937b9d4a70bb24ab71b97c165/app/models/service_template/filter.rb#L5) | ||
# which should be extended to retirement as part of later work | ||
# svc_rsc.resource_type != "ServiceTemplate" || self.class.include_service_template?(self, srr.id, parent_service) | ||
nh = attributes.except("id", "created_on", "updated_on", "type", "state", "status", "message") | ||
nh = attributes.except("id", "created_on", "updated_on", "type", "state", "status", "message", *self.class.virtual_attribute_names) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an alternative to @gmcculloug 's suggestion:
nh = attributes.slice(self.class.column_names)
.except!("id", "created_on", "updated_on", "type", "state", "status", "message")
Just makes it so that the list you are starting with is always what is available as columns from the database, and then it excludes columns from there, in the rare case that someone has fetch this current instance of this object was fetched using a custom SELECT
statement that included some other derived columns.
... Not that I would know anyone who would do that, for say, performance reasons or anything...
( ͡° ͜ʖ ͡°)
Note: I just used .except!
here to not dup the hash a second time, but that is probably peanuts in the grand scheme of things.
b483770
to
88f5cf0
Compare
@gmcculloug @NickLaMuro @anyone_with_more_power_than_me |
app/models/service_retire_task.rb
Outdated
|
||
# TODO: use changes here: https://github.com/ManageIQ/manageiq/pull/17996 to not have to filter by col_names | ||
# 17996 removes virtual attributes from @attrs list | ||
nh = attributes.slice(self.class.column_names).except!("id", "created_on", "updated_on", "type", "state", "status", "message") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@d-m-u slice
expects *keys
not an array of names. (https://apidock.com/rails/Hash/slice)
You need nh = attributes.slice(*self.class.column_names)...
When I run the command the way it is here I get an empty hash. Now my concern is that tests are passing with invalid data. 😱
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to correct call to slice and import test validation based on https://github.com/ManageIQ/manageiq/pull/17912/files#r219315906
Checked commits d-m-u/manageiq@fd5f912~...75f18ee with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
This changes the signature of the create_retire_subtask method to include the task, per the conversation @tinaafitz and @mkanoor and I had a week or so ago.
It's a fix for https://bugzilla.redhat.com/show_bug.cgi?id=1608958
Issue #17993 opened to track virtual attributes occasionally returned by
attributes
method.#17996 opened by Keenan to fix 17993.
Tested with
17996, works as expected. Yay. So the workaround for excluding virtual attributes directly from the service task creation is in this PRbecause I have no idea when 17996 will get in.There's no point in opening the rails pr as mentioned because it's fixed in 5.2 and a bunch of the attribute stuff changed.
TODO: use changes in #17996 to not have to filter out virtual attrs from nh attr list.... update:
17996is merged and #18019 opened to clean up the now-defunct TODO.