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 pluck
and select
with from
if from
has original table name
#35360
Conversation
This is caused by 0ee96d1. Since rails#18744, `select` columns doesn't be qualified by table name if using `from`. 0ee96d1 follows that for `pluck` as well. But people depends that `pluck` columns are qualified even if using `from`. So I've fixed that to be qualified if `from` has the original table name to keep the behavior as much as before. Fixes rails#35359.
def test_select_with_subquery_in_from_uses_original_table_name | ||
relation = Comment.joins(:post).select(:id).order(:id) | ||
subquery = Comment.from(Comment.all, Comment.quoted_table_name).joins(:post).select(:id).order(:id) | ||
assert_equal relation.map(&:id), subquery.map(&:id) |
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.
Weird... This test isn't failed locally... I suspect a bug on SQLite3...
https://travis-ci.org/rails/rails/jobs/496726410#L1198-L1208
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.
It did fail on buildkite as well https://buildkite.com/rails/rails/builds/58981
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.
ah... skipped on buildkite as well for now a333ba3.
…` on Travis I'm not sure why the test is failed on Travis, it passed on locally. I suspect that failure is a bug on SQLite3, so just skip the test for now, since it was not covered by before. https://travis-ci.org/rails/rails/jobs/496726410#L1198-L1208
Fix `pluck` and `select` with `from` if `from` has original table name
After rails#35360 was merged we bumped Rails again and while the test script we sent passed we still had the same failures. I debugged a bit and found that the new code assumes that the `from` is passing only a table name and that we can get that from `name` or from `value` but there are cases (like this test case) where you may not pass a name along with the `FromClause` and the value may not be just a table name. This test demonstrates what happens when you add an index to the from clause.
…X hint rails#35360 allows table name qualified if `from` has original table name. But that is still too strict. We have a valid use case that `from` with INDEX hint (e.g. `from("comments USE INDEX (PRIMARY)")`). So I've relaxed the table name detection in `from` to allow any extension like INDEX hint. Fixes rails#35359.
This is caused by 0ee96d1.
Since #18744,
select
columns doesn't be qualified by table name ifusing
from
. 0ee96d1 follows that forpluck
as well.But people depends that
pluck
columns are qualified even if usingfrom
.So I've fixed that to be qualified if
from
has the original table nameto keep the behavior as much as before.
Fixes #35359.
cc @eileencodes