Skip to content

Commit

Permalink
Merge pull request rails#50395 from Shopify/fix-find-or-create
Browse files Browse the repository at this point in the history
Fix `Relation#transaction` to not apply a default scope
  • Loading branch information
byroot authored Dec 19, 2023
2 parents 462e8e8 + 8c9ff7c commit 18b8f37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/delegation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def #{method}(...)
:to_sentence, :to_fs, :to_formatted_s, :as_json,
:shuffle, :split, :slice, :index, :rindex, to: :records

delegate :primary_key, :connection, to: :klass
delegate :primary_key, :connection, :transaction, to: :klass

module ClassSpecificRelation # :nodoc:
extend ActiveSupport::Concern
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/cases/transactions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def test_rollback_dirty_changes
assert_equal title_change, topic.changes["title"]
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?
def test_rollback_dirty_changes_even_with_raise_during_rollback_removes_from_pool
topic = topics(:fifth)
Expand Down

0 comments on commit 18b8f37

Please sign in to comment.