-
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
Remove generic object from all related services before destroy #17679
Remove generic object from all related services before destroy #17679
Conversation
@miq-bot add_label bug |
app/models/generic_object.rb
Outdated
@@ -200,4 +201,10 @@ def _call_automate(method_name, *args) | |||
ws = MiqAeEngine.deliver(options) | |||
ws.root['method_result'] | |||
end | |||
|
|||
def remove_go_from_all_related_services | |||
ServiceResource.where(:resource_id => id).each do |resource| |
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.
Use :resource => self
. The resource
association is polymorphic, if any other object type happens to share the same ID as this generic object you would delete it. 😱
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.
@gmcculloug changed. Thanks
app/models/generic_object.rb
Outdated
|
||
def remove_go_from_all_related_services | ||
ServiceResource.where(:resource => self).each do |resource| | ||
remove_from_service(Service.find_by(:id => resource.service_id)) |
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.
You do not have to lookup the service as it is an association of the resource
object. Also, I am not sure if we need to protect if resource.service
is nil
but in case:
remove_from_service(resource.service)) if resource.service
LTGM other than the only comment GM made. |
Checked commits pkomanek/manageiq@06cb29e~...9e1380e with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
Calling the
generic_objects
method from theservice
model returns array of GenericObjects and nils(for allready destroyed objects), which makes some UI crashes. So we decided to remove a GO from all related services in the#before_destroy
callback. This PR is based on the BZ bellow.Links [Optional]
https://bugzilla.redhat.com/show_bug.cgi?id=1595149