-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
Incorrect reference to table alias. #1153
Comments
Thank you @MrJoy could this awesome write-up be converted into a PR with the failing tests? |
Based on the git bisect result, this behavior had been introduced by this commit between Rails v6.0.0 and v6.0.1. Then it has been addressed by this commit, which will be available if Rails 6.0.4 is released. |
Yes. I think we can merge #1176 and skip this test on v6.0.3. |
I see, then we need to work on the fix for sure! I don't care whether we merge the skipped tests first or together with the future fix. |
I changed 6.0.3.4 version to |
I think this could be a similar issue like #1119. I had the same problems where a table with alias in |
…-alias Add spec described in #1153.
Reverted #1263 |
…ncorrect-reference-to-table-alias Revert "Add spec described in #1153."
@scarroll32 Curious about the revert here. Should I re-file my PR so that there's something open to work against if/when y'all have time to investigate the bug? |
@MrJoy hey there, thanks for the ping. It was reverted as the CI failed on merge. If you can get the CI to pass, we can definitely merge it. |
@scarroll32 Well, that's the challenging part. The code for Ransack is a bit brain-bendy to me, and I'm not deeply-rooted in the lineage of Rails enough to feel comfortable addressing version-specific test failures. I could re-submit the PR with the tests marked as pending/skip, perhaps? Alternatively, if you have an intuition around the root cause you could use to offer me a roadmap I could take a stab at fixing it. I can't guarantee I'll be super useful on that front, however. A third alternative would just be to leave an open PR -- possibly as a draft, if that's something I can do as an external contributor, so that it's there if/when your crew have the time/inclination to look at it. |
@MrJoy sure thing, it looks like it can't find a column, but if you want to just create the merged PR with a note linking back here, perhaps someone will pick it up. Thanks for your contribution! |
Not much of a crew here, but I'll try to look at it eventually. |
Finally got a fix contributed for this by @oneiros, closing! |
I know this issue seems related to a couple others, but I think it may involve a slightly novel twist.
I have an indirect association I want to ransack, while also ransacking the intermediate association. It matters greatly what order these query options are provided to
.ransack
. If they follow the natural ordering (intermediate table first), all is well. If they go in the opposite order, then I wind up with a bad query because theLEFT OUTER JOIN
aliases the table as<intermediate_table_name>_<direct_table_name>_join
, but theWHERE
clause refers to<intermediate_table_name>_<direct_table_name>
.This behavior is novel starting with Rails 6.0.1, and I have a nice little repro case:
Doing my best to dig through Ransack internals I found Arel objects being created that include
TableAlias
objects that have the nameaccounts_google_calendars
, so I started looking for where the_join
was added. I believe I found where it's hiding in ActiveRecord, and have a stack trace:I'm not sure where the aliasing is getting out of sync, but somewhere along the way one part of the Arel tree seems to think one thing, and another part thinks another thing.
I wish I could send you a patch, but Ransack and Arel are very complex and I lack enough context to even properly understand what's going on, let alone come up with a patch that won't break other things.
The text was updated successfully, but these errors were encountered: