Difference between ActiveRecord network between Rails 4.1 and 4.2?

we upgraded our application from Rails 4.1.14 to 4.2.5.1 and hit the following problem:

string = "SomeString" ar_model = SomeArModel.new ar_model.some_attribute = string # next line is true for 4.1, but fails for 4.2 ar_model.some_attribute.object_id == string.object_id 

Apparently, object setters duplicate every object (if I have an array, every object inside will also be tricked), and I wonder if this is intended and part of some new security function?

Update

I am using ruby-2.2.2p95 for both versions of rails. For reference, I made a small project:

 rails new testproject rails g model Building name:string rails db:migrate rails c >> b = Building.new >> name = "Testname" >> b.name = name >> name.object_id # => 70199493308960 >> b.name.object_id # => 70199493278780 

Subsequently, I only changed the version of Rails to 4.1.14 in the Gemfile and tried again => both objects are the same. Therefore, it cannot rely solely on the Ruby version ...

Update2

This also applies to ruby-2.2.3 and JRuby 9.0.4.0 ... ar_model.attributes_before_type_cast['some_attribute'] contains the real object.

+6
source share
1 answer

According to Rails developers, this is by design:

https://github.com/rails/rails/issues/23430

0
source

All Articles