mirror of https://github.com/rails/rails
Fix `Relation#transaction` to not apply a default scope
Fix: https://github.com/rails/rails/issues/50368 When called on a scope it would go through the default scoping delegator that applies a default scope, which make no sense.
This commit is contained in:
parent
462e8e8b1c
commit
8c9ff7cdd8
|
@ -101,7 +101,7 @@ module ActiveRecord
|
||||||
:to_sentence, :to_fs, :to_formatted_s, :as_json,
|
:to_sentence, :to_fs, :to_formatted_s, :as_json,
|
||||||
:shuffle, :split, :slice, :index, :rindex, to: :records
|
:shuffle, :split, :slice, :index, :rindex, to: :records
|
||||||
|
|
||||||
delegate :primary_key, :connection, to: :klass
|
delegate :primary_key, :connection, :transaction, to: :klass
|
||||||
|
|
||||||
module ClassSpecificRelation # :nodoc:
|
module ClassSpecificRelation # :nodoc:
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
|
@ -36,6 +36,14 @@ class TransactionTest < ActiveRecord::TestCase
|
||||||
assert_equal title_change, topic.changes["title"]
|
assert_equal title_change, topic.changes["title"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_transaction_does_not_apply_default_scope
|
||||||
|
# Regression test for https://github.com/rails/rails/issues/50368
|
||||||
|
topic = topics(:fifth)
|
||||||
|
Topic.where.not(id: topic.id).transaction do
|
||||||
|
assert_not_nil Topic.find(topic.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if !in_memory_db?
|
if !in_memory_db?
|
||||||
def test_rollback_dirty_changes_even_with_raise_during_rollback_removes_from_pool
|
def test_rollback_dirty_changes_even_with_raise_during_rollback_removes_from_pool
|
||||||
topic = topics(:fifth)
|
topic = topics(:fifth)
|
||||||
|
|
Loading…
Reference in New Issue