aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2012-05-21 14:57:04 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2012-05-21 14:57:04 -0700
commitcb847b9f2e56eeff737323d9a42a2a0a6c23804d (patch)
treec22d2cf52201134bea2e32bc15706b0d998d8133 /activerecord/lib
parent03886d817307e091024ff3bd26844447abd8c408 (diff)
downloadrails-cb847b9f2e56eeff737323d9a42a2a0a6c23804d.tar.gz
rails-cb847b9f2e56eeff737323d9a42a2a0a6c23804d.tar.bz2
rails-cb847b9f2e56eeff737323d9a42a2a0a6c23804d.zip
Restore the frozen state on rollback. Fixes #6417.
Currently, when saving a frozen record, an exception would be thrown which causes a rollback. However, there is a bug in active record that "defrost" the record as a side effect: >> t = Topic.new => #<Topic id: nil, ...> >> t.freeze => #<Topic id: nil, ...> >> t.save RuntimeError: can't modify a frozen Hash >> t.frozen? => false >> t.save => true This patch fixes the bug by explictly restoring the frozen state on the attributes Hash after every rollback.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/transactions.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb
index 30e1035300..9cb9b4627b 100644
--- a/activerecord/lib/active_record/transactions.rb
+++ b/activerecord/lib/active_record/transactions.rb
@@ -329,7 +329,8 @@ module ActiveRecord
@_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) - 1
if @_start_transaction_state[:level] < 1
restore_state = remove_instance_variable(:@_start_transaction_state)
- @attributes = @attributes.dup if @attributes.frozen?
+ was_frozen = @attributes.frozen?
+ @attributes = @attributes.dup if was_frozen
@new_record = restore_state[:new_record]
@destroyed = restore_state[:destroyed]
if restore_state.has_key?(:id)
@@ -338,6 +339,7 @@ module ActiveRecord
@attributes.delete(self.class.primary_key)
@attributes_cache.delete(self.class.primary_key)
end
+ @attributes.freeze if was_frozen
end
end
end