aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-04-24 12:11:51 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-04-24 12:11:51 -0700
commit4e3eca480974fdad3d4dae475959b3d2638e2b33 (patch)
treec0e00cf34d93953e0a6e600608b91ac98379ff07
parent4e7fa91332ea08aa29e69e905413abba78d93d78 (diff)
parent8c8d34fa55b471858b7466789830ff936c550a8f (diff)
downloadrails-4e3eca480974fdad3d4dae475959b3d2638e2b33.tar.gz
rails-4e3eca480974fdad3d4dae475959b3d2638e2b33.tar.bz2
rails-4e3eca480974fdad3d4dae475959b3d2638e2b33.zip
Merge pull request #10330 from kennyj/fix_10067
Serialized column should not be wrapped twice. Fix #10067.
-rw-r--r--activerecord/CHANGELOG.md7
-rw-r--r--activerecord/lib/active_record/persistence.rb2
-rw-r--r--activerecord/test/cases/serialized_attribute_test.rb14
3 files changed, 22 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index d47a23b8f5..a171ee8293 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,12 @@
## Rails 4.0.0 (unreleased) ##
+* Fix a SystemStackError problem when using time zone aware or serialized attributes.
+ In current implementation, we re-use `column_types` argument when initiating an instance.
+ If an instance have serialized or timezone aware attributes,
+ column_types is wrapped multiple times in `decorate_columns` method. Thus the above error occurs.
+
+ *Dan Erikson & kennyj*
+
* Fix for a regression bug in which counter cache columns were not being updated
when record was pushed into a has_many association. For example:
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 42cece3ad0..59f8e90e7a 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -51,7 +51,7 @@ module ActiveRecord
# how this "single-table" inheritance mapping is implemented.
def instantiate(record, column_types = {})
klass = discriminate_class_for_record(record)
- column_types = klass.decorate_columns(column_types)
+ column_types = klass.decorate_columns(column_types.dup)
klass.allocate.init_with('attributes' => record, 'column_types' => column_types)
end
diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb
index 726338db14..d0e012902e 100644
--- a/activerecord/test/cases/serialized_attribute_test.rb
+++ b/activerecord/test/cases/serialized_attribute_test.rb
@@ -1,5 +1,6 @@
require 'cases/helper'
require 'models/topic'
+require 'models/reply'
require 'models/person'
require 'models/traffic_light'
require 'bcrypt'
@@ -241,4 +242,17 @@ class SerializedAttributeTest < ActiveRecord::TestCase
assert_equal [], light.state
assert_equal [], light.long_state
end
+
+ def test_serialized_columh_should_not_be_wrapped_twice
+ Topic.serialize(:content, MyObject)
+
+ myobj = MyObject.new('value1', 'value2')
+ Topic.create(content: myobj)
+ Topic.create(content: myobj)
+
+ Topic.all.each do |topic|
+ type = topic.instance_variable_get("@columns_hash")["content"]
+ assert !type.instance_variable_get("@column").is_a?(ActiveRecord::AttributeMethods::Serialization::Type)
+ end
+ end
end