-
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
New and improved Field.is_field?() #17801
Conversation
Fixes issue when MiqExpression engine is a regular expression and the field looks like "Model-field" but the attribute doesn't exist Example: if there is vm named "Lan-yuri" than this expression Virtual Machine : Name REGULAR EXPRESSION MATCHES "L+" triggers error https://bugzilla.redhat.com/show_bug.cgi?id=1581853
ae4765d
to
4dc6d18
Compare
Checked commit kbrock@4dc6d18 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
begin | ||
parsed_params[:model_name] = parsed_params[:model_name].classify.safe_constantize | ||
rescue LoadError # issues for case sensitivity (e.g.: VM vs vm) | ||
parsed_params[:model_name] = nil |
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 thought safe_constantize's purpose is to never raise a LoadError, but to return nil instead. How would the LoadError path ever occur?
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.
"Vm".safe_constantize # good
nil.safe_constantize # good
"XYZ".safe_constantize # good
"VM".safe_constantize
LoadError: Unable to autoload constant VM, expected app/models/vm.rb to define 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.
@Fryguy "Vm" fails for me all the time, but having trouble reproducing this for a rails PR.
safe_constantize does not catch LoadError
- so it makes some sense.
This may be an auto_load path
issue
👍 It looks good, there is no need to introduce new method in #17760 |
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.
Looks good to me too 👍
New and improved Field.is_field?() (cherry picked from commit ec091b9) https://bugzilla.redhat.com/show_bug.cgi?id=1615465
Gaprindashvili backport details:
|
@yrudman and I had discussed this and I wanted to capture my local code before I lost it.
This is an alternate to #17760
Fixes issue when MiqExpression engine is a regular expression
and the field looks like "Model-field" but the attribute doesn't exist
Example: if there is vm named "Lan-yuri" than this expression
Virtual Machine : Name REGULAR EXPRESSION MATCHES "L+" triggers error
https://bugzilla.redhat.com/show_bug.cgi?id=1581853