Skip to content

Commit 9a25710

Browse files
authored
Merge pull request rails#46473 from nvasilevski/remove-state-invalidate-indirection
Add `invalidate!` directly to `Transaction`
2 parents e357d72 + 53f4a4b commit 9a25710

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

activerecord/lib/active_record/connection_adapters/abstract/transaction.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ def add_record(record, _ = true); end
8383
def restartable?; false; end
8484
def dirty?; false; end
8585
def dirty!; end
86+
def invalidate!; end
8687
end
8788

8889
class Transaction # :nodoc:
8990
attr_reader :connection, :state, :savepoint_name, :isolation_level
9091
attr_accessor :written, :written_indirectly
9192

93+
delegate :invalidate!, to: :@state
94+
9295
def initialize(connection, isolation: nil, joinable: true, run_commit_callbacks: false)
9396
@connection = connection
9497
@state = TransactionState.new
@@ -496,7 +499,7 @@ def within_new_transaction(isolation: nil, joinable: true)
496499
begin
497500
commit_transaction
498501
rescue ActiveRecord::ConnectionFailed
499-
transaction.state.invalidate! unless transaction.state.completed?
502+
transaction.invalidate! unless transaction.state.completed?
500503
raise
501504
rescue Exception
502505
rollback_transaction(transaction) unless transaction.state.completed?

activerecord/lib/active_record/connection_adapters/abstract_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ def invalidate_transaction(exception)
10211021
return unless exception.is_a?(TransactionRollbackError)
10221022
return unless savepoint_errors_invalidate_transactions?
10231023

1024-
current_transaction.state.invalidate! if current_transaction.open?
1024+
current_transaction.invalidate!
10251025
end
10261026

10271027
def retryable_query_error?(exception)

0 commit comments

Comments
 (0)