-
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 error importing Widget on Custom Report page #16034
Fix error importing Widget on Custom Report page #16034
Conversation
@@ -37,6 +38,10 @@ def import(fd, options = {}) | |||
raise "Invalid YAML file" | |||
end | |||
|
|||
if options.key?(:expected_class) && (options[:expected_class] != reps[0].keys.first) | |||
raise _("Incorrect format: Expected #{options[:expected_class]} and received #{reps[0].keys.first}") | |||
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.
@bmclaughlin I'm ok with this check, but it looks like doing this for MiqReport
(ManageIQ/manageiq-ui-classic#2227) would negate the need for the rescue
below on line 59: # for the legacy MiqReport
as we would never get to that code.
@gtanzillo Can you comment on this or recommend someone?
Thinking more about this maybe a better approach is to create a From what I can tell three classes use this mixin: MiqReport, MiqWidget and MiqPolicy. Both MiqReport and MiqWidget expect the root of the import to be the same class name. However, MiqPolicy supports MiqPolicy, MiqPolicySet and MiqAlert. The mixin could contain the validation method that checks the the name matches the class name and the classes would expose a constant that defines the Something like this: def import(fd, options = {})
fd.rewind # ensure to be at the beginning as the file is read multiple times
begin
reps = YAML.load(fd.read)
validate_import_data(reps)
rescue Psych::SyntaxError => err
_log.error("Failed to load from #{fd}: #{err}")
raise "Invalid YAML file"
end
return reps, import_from_array(reps, options)
end
def validate_import_data(data)
data_class_name = data.first.keys.first
if !self::IMPORT_CLASS_NAMES.include?(data_class_name)
raise _("Incorrect format: Expected #{self::IMPORT_CLASS_NAMES.join(", ")} and received #{data_class_name}")
end
end Then in module MiqPolicy::ImportExport
extend ActiveSupport::Concern
IMPORT_CLASS_NAMES = %w(MiqPolicy MiqPolicySet MiqAlert)
... @gtanzillo @eclarizio Thoughts? |
@gmcculloug Yeah, I like this idea, and I would even further look into a way to incorporate the already existing |
5c14a4a
to
6dc3067
Compare
@gmcculloug, implemented your idea, much better solution than what I had originally. Thanks! @eclarizio, or perhaps |
b3f0a84
to
20c737c
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.
@bmclaughlin My original point was mostly directed at attempting to encapsulate the validation in a different class, but I think since we're not really validating the data, just ensuring that the class is correct, I agree with your other point of changing the name of the method to validate_import_class
instead of validate_import_data
. Or maybe validate_import_data_class
, but either way, I think validate_import_data
implies it does more than it really does.
20c737c
to
f810cf8
Compare
@bmclaughlin Specs are failing because they still references the old method name. |
f810cf8
to
252e6d1
Compare
@@ -56,4 +56,18 @@ | |||
expect { subject.import(@fd) }.to raise_error("Invalid YAML file") | |||
end | |||
end | |||
|
|||
context ".validate_import_data" do |
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.
Missed one. 😱
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.
So close...
For our final act, can you drop the first commit since it's not being used and squash the others? |
ccf92cd
to
d5ae286
Compare
Somehow you pulled in one of Jillian's PRs!?! |
d5ae286
to
b26b013
Compare
Checked commit bmclaughlin@b26b013 with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0 |
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.
👍
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.
LGTM 👍
Fix error importing Widget on Custom Report page (cherry picked from commit 16602fa) https://bugzilla.redhat.com/show_bug.cgi?id=1500029
Fine backport details:
|
…rt-error Fix error importing Widget on Custom Report page (cherry picked from commit 16602fa) https://bugzilla.redhat.com/show_bug.cgi?id=1500029
Fixes an exception to a much more user friendly flash message.
@miq-bot add_labels bug, core, ui
https://bugzilla.redhat.com/show_bug.cgi?id=1442728