Skip to content

Commit

Permalink
Merge pull request #35918 from kamipo/lazy_sync_with_transaction_stat…
Browse files Browse the repository at this point in the history
…e_on_destroy

Lazy sync with transaction state on destroy
  • Loading branch information
kamipo committed Apr 12, 2019
2 parents 186566c + bcb0fb7 commit ef0c5fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion activerecord/lib/active_record/core.rb
Expand Up @@ -466,6 +466,7 @@ def freeze

# Returns +true+ if the attributes hash has been frozen.
def frozen?
sync_with_transaction_state
@attributes.frozen?
end

Expand Down Expand Up @@ -583,7 +584,7 @@ def initialize_internals_callback
end

def thaw
if frozen?
if @attributes.frozen?
@attributes = @attributes.dup
end
end
Expand Down
1 change: 0 additions & 1 deletion activerecord/lib/active_record/persistence.rb
Expand Up @@ -530,7 +530,6 @@ def delete
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
Expand Down
14 changes: 8 additions & 6 deletions activerecord/test/cases/transactions_test.rb
Expand Up @@ -26,13 +26,15 @@ def test_persisted_in_a_model_with_custom_primary_key_after_failed_save
def test_raise_after_destroy
assert_not_predicate @first, :frozen?

assert_raises(RuntimeError) {
Topic.transaction do
@first.destroy
assert_predicate @first, :frozen?
raise
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
Expand Down

0 comments on commit ef0c5fe

Please sign in to comment.