Merge pull request #35918 from kamipo/lazy_sync_with_transaction_state_on_destroy

Lazy sync with transaction state on destroy
This commit is contained in:
Ryuta Kamizono 2019-04-12 22:11:38 +09:00 committed by GitHub
commit ef0c5fe0d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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