Skip to content
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

Merged
merged 1 commit into from
Aug 9, 2018

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Aug 3, 2018

@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

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
@miq-bot
Copy link
Member

miq-bot commented Aug 4, 2018

Checked commit kbrock@4dc6d18 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 0 offenses detected
Everything looks fine. 👍

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
Copy link
Member

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?

Copy link
Member Author

@kbrock kbrock Aug 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fryguy

"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

Copy link
Member Author

@kbrock kbrock Aug 6, 2018

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

@yrudman
Copy link
Contributor

yrudman commented Aug 6, 2018

👍 It looks good, there is no need to introduce new method in #17760

Copy link
Member

@gtanzillo gtanzillo left a 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 👍

@gtanzillo gtanzillo added this to the Sprint 92 Ending Aug 13, 2018 milestone Aug 9, 2018
@gtanzillo gtanzillo merged commit ec091b9 into ManageIQ:master Aug 9, 2018
@kbrock kbrock deleted the check-if-valid-field branch August 9, 2018 16:01
simaishi pushed a commit that referenced this pull request Sep 11, 2018
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 85b2eb61b57efe68664026b6607f80d62a3c1c9e
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Thu Aug 9 09:37:02 2018 -0400

    Merge pull request #17801 from kbrock/check-if-valid-field
    
    New and improved Field.is_field?()
    (cherry picked from commit ec091b9a98735b8a5b91aef77d04ef34955a219b)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1615465

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants