-
Notifications
You must be signed in to change notification settings - Fork 900
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
Make MiqExpression#contains work in Rails 5.2 #20051
Conversation
171bc0a
to
2ab6ce3
Compare
^ fixed cops |
Will this replace this commit on the rails-5-2 branch? jrafanie@1829461 |
Followup: Is this Rails 5.2 only, or can we merge this into master now? |
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 think I am 50/50 on grasping this, but left some comments to start with for now. Mostly are docs/clarification since I am still trying to understand this PR.
@kbrock I think the PR description could really use some example cases that are being fixed here. The specs you add only test the private methods, and don't really paint a picture at what the over "SQL" or |
2a29306
to
e8600f7
Compare
heh. added a few more use cases and test @NickLaMuro This started out trying to get this functionality working on rails 5.2. It was tricky to then get it to work on both versions. This was a "simplification" by using rails to build the query for us, so we didn't have to create the active record objects or handle 2 different active record interfaces. It ended up becoming an enhancement because rails did so much for us. I started adding tests/use cases for the edge cases (that had no chance of working before) |
277ce65
to
806177f
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.
Some comments after talking with @kbrock out of band.
3b8b650
to
b932ef2
Compare
Added the visitor. @NickLaMuro is this closer to what you had in mind? |
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 think I need to look at the visitor a bit more to make sure I fully understand things before I sign off, but I think I have enough critiques with what I have already to provide a first round of feedback.
|
||
# query: "hosts"."type" = 'abc' | ||
# result: "hosts"."type" = 'abc' | ||
# This doesn't make sense, but we saw this example |
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.
"saw this example" where? In specs? In production? In a magical fairy land where raw SQL is allowed to roam freely?
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.
This is how the parameter was coming into our code for our code example
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.
in miq test suite (thought it could have been another problem. who knows
expect(result).to be_nil | ||
end | ||
|
||
# query: <invalid> |
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.
Edit: Wow... that didn't come out right... let me try that again...
I feel like <invalid>
is not serving much of a purpose, helping to describe what <invalid>
is supposed to be, or where it might happen. Again, similar comment to the "but we saw this example" one.
22ef577
to
07334ad
Compare
90e0640
to
ac6aae8
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.
FYI about Arel::Visitors::Visitor
end | ||
end | ||
# rubocop:disable Naming/MethodName | ||
class RemoveEqualityVisitor < Arel::Visitors::Reduce |
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 exists in Rails 6... possibly in Rails 5.2 depending on what version of ActiveRecord
we bumped to in the upgrade:
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.
That said, it looks like it was effectively Arel::Visitors::Visitor
anyway.
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.
we can cross that bridge when we upgrade to 6.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.
This is a "I did a bundle open activerecord
and couldn't find this class", not a "this might be an issue in the future" thing. I see this being a problem right now, not later.
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.
https://github.com/rails/rails/blob/5-2-stable/activerecord/activerecord.gemspec#L34
5-1 uses v8 ==> https://github.com/rails/arel/blob/v8.0.0/lib/arel/visitors/reduce.rb
5-2 uses v9 ==> https://github.com/rails/arel/blob/v9.0.0/lib/arel/visitors/reduce.rb
I think it is good for rails 5.1 and 5.2.
rails 6.0 just merged it into a basic Visitor
ac6aae8
to
0ee8cdb
Compare
0ee8cdb
to
d81cb97
Compare
updated the typo and rebased to recent version of miq. hoping that fixes the rubygem fetch issue |
this is needed to support rails 5.2
d81cb97
to
c54488b
Compare
sorry nick. this contains a few rails 5.2 vs 5.1 switches. also, thinking I'll drop the traverser commit. Not really doing any good besides making it difficult to rebase stuff. |
That is fine. What I tend to do, though (and you don't have to), is copy the branch prior to dropping a commit like that, and push it to my fork for historical reference, and link it in the PR (assuming you don't prune it later). That way there is a way for someone to take a look at what was considered previously when looking back on this PR. |
Okay, if that is the case, I won't be reviewing further then. I have made my case against this multiple times, and still disagree with you on this. I don't think it will be productive having me review further. |
c54488b
to
a376ca6
Compare
a376ca6
to
6005c51
Compare
reverted this PR back to previous form with a visitor. I prefer new way #20110 |
6005c51
to
c97bafe
Compare
Checked commits kbrock/manageiq@6f099e9~...c97bafe with ruby 2.5.7, rubocop 0.69.0, haml-lint 0.28.0, and yamllint lib/miq_expression/remove_equality_visitor.rb
|
This pull request is not mergeable. Please rebase and repush. |
Closing this since this is the old form of the PR. |
make MiqExpression#contains work in rails 5.2
MiqExpression CONTAINS built up the sql for a contains clause.
This would only work with direct simple relations and broke in the upgrade to rails 5.2.
In this PR, rails was asked to build the sql for a query that is close. Then the extra nodes are removed.
There were bind variables that needed to be removed. We typically use just compile the query and turn into a sql literal. Unfortunately, sql
IN
clauses are picky about the parameter that they accept, so we needed to pass arel.The merge conditions code broke as well. We are patching it in this PR as well