-
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
Forcing default_value to an array, if the dynamic dropdown is multiselect #17272
Conversation
ed2df30
to
70f16ac
Compare
@miq-bot add_label 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.
See my comment about rearranging/adding a spec. Otherwise, looking good 👍
before(:each) do | ||
allow(dialog_field).to receive(:force_multi_value).and_return(false) | ||
end | ||
|
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.
I don't think this needs to be at the top level. It should be moved into a deeper context within the #values
describe method, and there needs to be a spec relevant to when it's set to false and when it's set to true.
describe "#values" do
# setup that exists
context "when the field is dynamic" do
# setup that exists
context "when force_multi_value is set to false" do
# this is where you would do your allow
context "when the default_value is included in the list of returned values" do
# this context already exists and you would simply reuse the tests here
end
end
context "when force_multi_value is set to true" do
# this is where you would do your allow, but return true
context "when the default_value is included in the list of returned values" do
# this is the same existing context but now force_multi_value is true and there
# would be different 'let(:default_value)' values, and different 'it' blocks
end
end
end
end
Actually, though, the relevant spec needs to be in the dialog_field_drop_down_list_spec.rb
because we need to make sure that the private method default_value_included?
isn't crashing like it was in the bug. So, similar to the contexts I provided above, but there's a few more in the drop down list spec that you will need to integrate.
Regardless, we definitely need a spec that proves the bug is fixed 😄
@miq-bot add_label gaprindashvili/yes |
@eclarizio is there anything else needed, if no, can this blocker be merged. |
@JPrause the specs are still missing. |
@romanblanco thanks for the update. We have dev complete on April 16. Will this be completed and merged by then? cc @eclarizio |
@JPrause Yes |
Testing that default_value is wrapped into an array, if the dynamic dialog field is multiselect
70f16ac
to
2cde07d
Compare
Checked commits romanblanco/manageiq@aa5511d~...2cde07d with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 spec/models/dialog_field_sorted_item_spec.rb
|
@@ -96,6 +96,9 @@ def sort_data(data_to_sort) | |||
end | |||
|
|||
def determine_selected_default_value | |||
if dynamic? && force_multi_value && !default_value.kind_of?(Array) |
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.
@romanblanco doesn't it make more sense to put this after the use_first_value_as_default unless default_value_included?(@raw_values)
line?
If you Array.wrap
first, default_value_included?
will never return true - doesn't this break it for some cases? (Like, always overwriting anything wrapped with the first value?)
Also, if use_first_value_as_default
does get called, it won't wrap the default value in the array (until you re-run this method twice).
Or is this intended?
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.
@himdel It does make more sense. You're right. I'll check again, but this seems more reasonable. Thanks!
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.
@himdel I've tried, and there's another problem while ordering a dialog containing dialog containing dynamic dropdown list after the changes you've suggested.
The workflow fails on 500 error because of calling collect
operation on nil
.
If this doesn't block the PR from merging, I'd say it'll be better to fix this in a following PR, as the situation is a bit confusing to me, and we want to merge this soon.
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.
Aaah, because #16978 overrides it to do some JSON magic, without making sure default_value
is a JSON... this is really broken :(
Looks like default_value
can be anything from an array to a JSON-encoded array string :(
I don't know. The fix looks buggy without it, but the bug looks larger than the fix :).
Cc @eclarizio
(Somebody needs to really decide when we do the conversion to json and back and make that consistent and get rid of all those "maybe it is an array, maybe it's a json or maybe it's a string" cases. Or do we need an actual_value
method? :) )
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.
Either way, I guess you need to know why you get that error @romanblanco.
Either use_first_value_as_default
is broken and should never be called in your situation.
Or it's supposed to be called and needs to be fixed too.
EDIT: IMO this may need a bigger rewrite ... looks like we're fixing random bugs again and again in this place .. and all of them could be fixed by actually fixing the field type in the DB.
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.
Does it look like this will be able to be merged for today's dev complete milestone?
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.
@himdel I think the line:
use_first_value_as_default unless default_value_included?(@raw_values)
is fine to stay as it is. The values list will always end up being an array of arrays, so there's no problem with use_first_value_as_default
. The issue is in default_value_included?
, because the default_value
can be either a single value, or multiple values, but string encoded (this is where the JSON.parse comes in). To fix this bug, I think that just needs to be modified to handle when the default value is not set, when it's multiple values, and when it's a single value.
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.
OK, no complaints for me then :)
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.
@eclarizio You may want to adjust your review, still shows up as ⚔️
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.
@eclarizio if this can be merged in the next few hours, we probably can get this into today's blocker-only build. If not, can you let me know so I can pass the info along.
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.
👍 I've seen it work :)
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.
Lets get this into the blocker build and then we can re-evaluate.
Forcing default_value to an array, if the dynamic dropdown is multiselect (cherry picked from commit 41f514d) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1568473
Gaprindashvili backport details:
|
Opening this PR instead of #17259
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1559030
The value of the is set to be an id of provider (ExtManagementSystem)
Steps for Testing/QA
methods
tab -> configuration -> add a new methodschema
tab -> configuration -> edit selected schemaexecute
-> type set tomethod
-> data type set toString
-> saveinstance
tab -> configuration -> add a new instancethe rest is from the BZ ticket:
Thanks for the help with setting up the expression method @pkomanek!