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.
def frozen?
sync_with_transaction_state
@attributes.frozen?
end
@ -583,7 +584,7 @@ module ActiveRecord
end
def thaw
if frozen?
if @attributes.frozen?
@attributes = @attributes.dup
end
end

View file

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

View file

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