-
Jean Boussier authored
Fix: https://github.com/rails/rails/issues/48652 Ref: https://github.com/rails/rails/pull/46048 Ref: https://github.com/rails/rails/issues/46044 Ref: https://github.com/rails/rails/pull/34303 Ref: https://github.com/rails/rails/pull/39160 Close: https://github.com/rails/rails/pull/48705 This deep_dup was introduced to prevent the value stored in the query cache to be later mutated. The problem is that `ActiveRecord::Base#dup` will return a copy of the record but with the primary key set to nil. One could argue that `#dup` shouldn't behave this way, but I think this ship has sailed (or has it?). My initial fix was to instead always call `type.cast` eagerly so that we'd dup serialized types in a more correct way. However there is a test that explictly ensure this doesn't happen: https://github.com/rails/rails/pull/39160 The reason isn't 100% clear to me, but if I get it correctly, it's to avoid a potentially costly operation upfront. So instead we only eagerly cast serialized attributes only, so protect against future mutations. Mutable types are still deep duped.
Jean Boussier authoredFix: https://github.com/rails/rails/issues/48652 Ref: https://github.com/rails/rails/pull/46048 Ref: https://github.com/rails/rails/issues/46044 Ref: https://github.com/rails/rails/pull/34303 Ref: https://github.com/rails/rails/pull/39160 Close: https://github.com/rails/rails/pull/48705 This deep_dup was introduced to prevent the value stored in the query cache to be later mutated. The problem is that `ActiveRecord::Base#dup` will return a copy of the record but with the primary key set to nil. One could argue that `#dup` shouldn't behave this way, but I think this ship has sailed (or has it?). My initial fix was to instead always call `type.cast` eagerly so that we'd dup serialized types in a more correct way. However there is a test that explictly ensure this doesn't happen: https://github.com/rails/rails/pull/39160 The reason isn't 100% clear to me, but if I get it correctly, it's to avoid a potentially costly operation upfront. So instead we only eagerly cast serialized attributes only, so protect against future mutations. Mutable types are still deep duped.
Loading