Skip to content

Commit 8c9ff7c

Browse files
committed
Fix Relation#transaction to not apply a default scope
Fix: rails#50368 When called on a scope it would go through the default scoping delegator that applies a default scope, which make no sense.
1 parent 462e8e8 commit 8c9ff7c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

activerecord/lib/active_record/relation/delegation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def #{method}(...)
101101
:to_sentence, :to_fs, :to_formatted_s, :as_json,
102102
:shuffle, :split, :slice, :index, :rindex, to: :records
103103

104-
delegate :primary_key, :connection, to: :klass
104+
delegate :primary_key, :connection, :transaction, to: :klass
105105

106106
module ClassSpecificRelation # :nodoc:
107107
extend ActiveSupport::Concern

activerecord/test/cases/transactions_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ def test_rollback_dirty_changes
3636
assert_equal title_change, topic.changes["title"]
3737
end
3838

39+
def test_transaction_does_not_apply_default_scope
40+
# Regression test for https://github.com/rails/rails/issues/50368
41+
topic = topics(:fifth)
42+
Topic.where.not(id: topic.id).transaction do
43+
assert_not_nil Topic.find(topic.id)
44+
end
45+
end
46+
3947
if !in_memory_db?
4048
def test_rollback_dirty_changes_even_with_raise_during_rollback_removes_from_pool
4149
topic = topics(:fifth)

0 commit comments

Comments
 (0)