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

Rails - Ruby 2.3 - Hash now responds to `to_proc` and `interpolate` blows up #25010

tlrdstd opened this issue May 13, 2016 · 4 comments


None yet
8 participants
Copy link

commented May 13, 2016


As of Ruby 2.3, Hash responds to to_proc This is a change from Ruby 2.2.

In ActiveRecord, the interpolate method (duplicated across ActiveRecord::Associations::JoinDependency::JoinAssociation, ActiveRecord::Associations::Association, and ActiveRecord::Associations::Preloader::Association) checks its input to see if it responds to to_proc.

I've seen a few bug reports on other projects that seem to be caused by this issue, but Casecommons/pg_search/issues/297 is the clearest.

Steps to reproduce

class Document < ActiveRecord::Base
  has_many :images, as: :parent

Calling Document.joins(:images).count triggers the error.

Expected behavior

In Ruby 2.2, if passed a Hash, this check returned false, and all was well - the query returns a count.

Actual behavior

In Ruby 2.3, if passed a Hash, this check returns true, and interpolate returns nil. This nil eventually gets passed to Arel.sql() and you get a no implicit conversion of nil into String error.

System configuration

Rails version:

Ruby version: 2.3.0

Temporary workaround

I've undefined to_proc on Hash, as I'm quite certain I have no code that relies on that:

class Hash
  undef_method :to_proc if self.method_defined?(:to_proc)

@tlrdstd tlrdstd changed the title Rails - ActiveRecord::Associations::JoinDependency::JoinAssociation - Bug on Ruby 2.3 Rails - Ruby 2.3 - Hash now responds to `to_proc` and `interpolate` blows up May 13, 2016

@arthurnn arthurnn self-assigned this May 13, 2016


This comment has been minimized.

Copy link

commented May 13, 2016

@tlrdstd thanks for letting us know.
We dont support rails 3.2 anymore. But i've been responsible for patching security level concerns there.
This is not a security issue, so we probably wont release a new version for it, however if you wanna work in a PR to fix it, i would be glad to merge it to 3-2-stable branch.



This comment has been minimized.

Copy link

commented May 13, 2016

I was running into a similar issue when testing against Ruby 2.3/Rails

I have an association that could be soft-deleted, but when upgrading to 2.3, the conditions were no longer being respected and deleted items were being returned.


class Product < ActiveRecord::Base
  has_many   :accessories, conditions: { deleted_at: nil }, dependent: :destroy

Thanks for digging in and finding out why. Your temporary workaround solves the problem for me as well.


This comment has been minimized.

Copy link

commented May 16, 2016

I've started working on a patch for this. Ran out of time this weekend, but at a quick glance, it does appear that several of the sqlite3 tests for ActiveRecord pass under Ruby 2.2 but fail under Ruby 2.3, which gives me hope for uncovering all the places affected by Hash.to_proc. I'll keep working on it this week.

tlrdstd added a commit to tlrdstd/rails that referenced this issue May 16, 2016

huerlisi added a commit to huerlisi/bookyt that referenced this issue Sep 7, 2016

chore(ruby): downgrade ruby version to 2.2.5
We're still using Rails 3.2 which does break on Ruby 2.3 on same cases.

This patch downgrades the ruby version to 2.2.5 in `.ruby-version`.

See: rails/rails#25010

This comment has been minimized.

Copy link

commented Oct 28, 2018

I just want to say thanks to @tlrdstd.
This ticket (and your PR!) just saved me a night of head scratching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.