Skip to content

Commit 334c271

Browse files
committed
Change the internal transaction state to be closed when the transaction is finalized
Before we were using the null pattern to calculate if the transaction is open or not, but there are cases like when the transaction is invalidated that we keep the transaction object around, and just change the state. The previous behavior made us miss cases where the transaction aren't not really open in our code. See 2f571a5. The public facing transaction object already had the behavior we are implementing here, so we are just aligning the internal transaction object to have the same behavior.
1 parent a146ee9 commit 334c271

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

activerecord/lib/active_record.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def self.all_open_transactions # :nodoc:
550550
if active_connection = pool.active_connection
551551
current_transaction = active_connection.current_transaction
552552

553-
if current_transaction.open? && current_transaction.joinable? && !current_transaction.state.invalidated?
553+
if current_transaction.open? && current_transaction.joinable?
554554
open_transactions << current_transaction
555555
end
556556
end

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ def dirty?
175175
end
176176

177177
def open?
178-
true
178+
!closed?
179179
end
180180

181181
def closed?
182-
false
182+
@state.finalized?
183183
end
184184

185185
def add_record(record, ensure_finalize = true)

activerecord/lib/active_record/transaction.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def open?
112112

113113
# Returns true if the transaction doesn't exist or is finalized.
114114
def closed?
115-
@internal_transaction.nil? || @internal_transaction.state.finalized?
115+
@internal_transaction.nil? || @internal_transaction.closed?
116116
end
117117

118118
alias_method :blank?, :closed?

0 commit comments

Comments
 (0)