-
Notifications
You must be signed in to change notification settings - Fork 898
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
Fix policy_events relationship on VmOrTemplate #17036
Conversation
app/models/vm_or_template.rb
Outdated
@@ -122,7 +122,7 @@ class VmOrTemplate < ApplicationRecord | |||
has_many :ems_events_src, :class_name => "EmsEvent" | |||
has_many :ems_events_dest, :class_name => "EmsEvent", :foreign_key => :dest_vm_or_template_id | |||
|
|||
has_many :policy_events, -> { where(["target_id = ? OR target_class = 'VmOrTemplate'", id]).order(:timestamp) }, :class_name => "PolicyEvent" | |||
has_many :policy_events, :class_name => "PolicyEvent" |
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.
Try has_many :policy_events, ->(vm) { where(["target_id = ? AND target_class = 'VmOrTemplate'", vm.id]).order(:timestamp) }, :foreign_key => "target_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.
@lfu yes, that works 👍 I wasn't sure that's what the query was supposed to be doing, since there was an "OR" in the original query
The policy_events relationship currently results in an internal server error because it is referencing "id" which is not valid Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1546995
Checked commit jntullo@adc676c with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 app/models/vm_or_template.rb
|
Fix policy_events relationship on VmOrTemplate (cherry picked from commit 9472102) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1558030
Gaprindashvili backport details:
|
Fix policy_events relationship on VmOrTemplate (cherry picked from commit 9472102) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1558032
Fine backport details:
|
Fix policy_events relationship on VmOrTemplate (cherry picked from commit 9472102) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1558032
Currently (back to Fine), the
policy_events
relationship onVmOrTemplate
is not working, and even if "fixed" to resolve the current internal server error, it does not appear to do what I think it was intended to be doing, which is simply returning all policy events with atarget_type
ofVmOrTemplate
Here's the step by step (although most of it is probably obvious):
does not work because it is referencing "id" which is an invalid reference, resulting in:
Adjusting the query to reference the VmOrTemplate id:
Still does not work, because it is expecting the
foreign_key
to bevm_or_template_id
. Even if that is fixed, it is doing anAND
on the foreign_key and thiswhere
clause, which would not return what thiswhere
is expecting.I got to this point and realized I think that this query is simply attempting to return all
policy_events
where thetarget_class
isVmOrTemplate
? But it is difficult to tell when the query was not working/does not make much sense in the first placeSanity check for what this query was supposed to be doing?
@miq-bot assign @gtanzillo
@miq-bot add_label bug, gaprindashvili/yes, fine/yes
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1546995