1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Lazy sync with transaction state on destroy

This reverts commit 58410b3d56.

If we have any implicit commit/rollback callbacks, it is necessary to
add record to transaction explicitly like `:touch_deferred_attributes`.

5f261d04d6/activerecord/lib/active_record/touch_later.rb (L9)
5f261d04d6/activerecord/lib/active_record/touch_later.rb (L25)

But I can't find any other implicit commit/rollback callbacks in our
code base at least now.

I think the `self.class.connection.add_transaction_record(self)` line
doesn't cover any behavior.
This commit is contained in:
Ryuta Kamizono 2019-04-10 19:26:15 +09:00
parent 5f261d04d6
commit bcb0fb7927
3 changed files with 10 additions and 8 deletions

View file

@ -466,6 +466,7 @@ module ActiveRecord
# Returns +true+ if the attributes hash has been frozen. # Returns +true+ if the attributes hash has been frozen.
def frozen? def frozen?
sync_with_transaction_state
@attributes.frozen? @attributes.frozen?
end end
@ -583,7 +584,7 @@ module ActiveRecord
end end
def thaw def thaw
if frozen? if @attributes.frozen?
@attributes = @attributes.dup @attributes = @attributes.dup
end end
end end

View file

@ -530,7 +530,6 @@ module ActiveRecord
def destroy def destroy
_raise_readonly_record_error if readonly? _raise_readonly_record_error if readonly?
destroy_associations destroy_associations
self.class.connection.add_transaction_record(self)
@_trigger_destroy_callback = if persisted? @_trigger_destroy_callback = if persisted?
destroy_row > 0 destroy_row > 0
else else

View file

@ -26,13 +26,15 @@ class TransactionTest < ActiveRecord::TestCase
def test_raise_after_destroy def test_raise_after_destroy
assert_not_predicate @first, :frozen? assert_not_predicate @first, :frozen?
assert_raises(RuntimeError) { assert_not_called(@first, :rolledback!) do
Topic.transaction do assert_raises(RuntimeError) do
@first.destroy Topic.transaction do
assert_predicate @first, :frozen? @first.destroy
raise assert_predicate @first, :frozen?
raise
end
end end
} end
assert_not_predicate @first, :frozen? assert_not_predicate @first, :frozen?
end end