From a0482d39110860272a056593e0e5c6e2ef4d75b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 19 Sep 2018 23:58:43 -0400 Subject: Make a deep copy of the _default_attributes in column_defaults When column_defaults is called it calls `value` on each instance of Attribute inside the _default_attributes set. Since value is memoized in the Attribute instance and that Attribute instance is shared across all instances of a model the next call to the default value will be memozied not running the proc defined by the user. Fixes #33031. --- activerecord/lib/active_record/model_schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/model_schema.rb') diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 694ff85fa1..9b985e049b 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -375,7 +375,7 @@ module ActiveRecord # default values when instantiating the Active Record object for this table. def column_defaults load_schema - @column_defaults ||= _default_attributes.to_hash + @column_defaults ||= _default_attributes.deep_dup.to_hash end def _default_attributes # :nodoc: -- cgit v1.2.3