rails / arel

A Relational Algebra
2.06k stars 390 forks source link

Expression in `in` is broken in 7.1.4 and 8.0.0 #531

Closed blackst0ne closed 6 years ago

blackst0ne commented 6 years ago

I am upgrading a rails 4.2 application to 5.0.
I have some constructions based on arel which stopped working on arel 7.1.4 (rails 5.0.6).

I have tested them on these versions:

Code (simplified for readability) is this:

# Arel 6.0.4 and 9.0.0
> sql = Arel.sql(User.select(:id).to_sql)
=> "SELECT \"users\".\"id\" FROM \"users\""
> User.where(User.arel_table[:id].in(sql)).to_sql
=> "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" IN (SELECT \"users\".\"id\" FROM \"users\")"

# Arel 7.1.4 and 8.0.0
> sql = Arel.sql(User.select(:id).to_sql)
=> "SELECT \"users\".\"id\" FROM \"users\""
> User.where(User.arel_table[:id].in(sql)).to_sql
=> "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" IN (0)"

What can I do to get my code work again on 7.1.4 and 8.0.0 (as I'm going to upgrade to rails 5.1 later)?

blackst0ne commented 6 years ago

/cc @matthewd @rafaelfranca

yorickpeterse commented 6 years ago

For clarification: the Rails application in question is GitLab's Rails application.

rafaelfranca commented 6 years ago

First first step is trying to find which commit fixed it on 9.0. After that we can backport to the other versions.

blackst0ne commented 6 years ago

I checked locally. It seems Arel is not affected, everything is just fine. :thinking:

Checking ActiveRecord...

matthewd commented 6 years ago

Per #523, Arel development is moving to rails/rails.

If this issue is still relevant, please consider reopening it over there. (Note that the Rails repository does not accept feature request issues, and requires reproduction steps that rely on Active Record's documented API.)

andsip commented 2 years ago

First first step is trying to find which commit fixed it on 9.0. After that we can backport to the other versions.

I think this was fixed in 9.0.0 via b416fca3.