From 98faa2a6a12e849119b60c72b08a25b03d3c867c Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Thu, 3 Nov 2016 13:55:46 -0400 Subject: [PATCH] Don't assign default attributes until after loading schema If the call to `.define_attribute_methods` actually ends up loading the schema (*very* hard to do, as it requires the object being created without `allocate` having been called, but it can be done by manually calling `initialize` from inside `marshal_load` if you're crazy), the value of `_default_attributes` will change from that call. --- activerecord/lib/active_record/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 0a9c06ba59..1fbe374ade 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -330,8 +330,8 @@ module ActiveRecord # # Instantiates a single new object # User.new(first_name: 'Jamie') def initialize(attributes = nil) - @attributes = self.class._default_attributes.deep_dup self.class.define_attribute_methods + @attributes = self.class._default_attributes.deep_dup init_internals initialize_internals_callback