Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/active_record/pg_extensions/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def #{kind}(local: false)
@#{kind} = timeout
# If we have set an explicit timeout, the transaction has state that must be materialized
# separately from any other transaction, so it cannot be `restartable`
dirty! unless ::Rails.version < '7.1'
dirty!
return unless materialized?
connection.set(#{kind.inspect}, "\#{(timeout * 1000).to_i}ms", local: true)
end
Expand Down
10 changes: 2 additions & 8 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ def executed_statements
@executed_statements ||= []
end

methods = if Rails.version < "7.1"
%w[execute exec_no_cache exec_cache]
else
%w[internal_execute exec_no_cache exec_cache]
end
methods.each do |method|
%w[internal_execute exec_no_cache exec_cache].each do |method|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(statement, *, **)
materialize_transactions # this still needs to get called, even if we skip actually executing
Expand All @@ -47,8 +42,7 @@ def #{method}(statement, *, **)
# we can't actually generate a dummy one of these, so we just query the db with something
# that won't return anything
def empty_pg_result
conn = (::Rails.version < "7.1") ? @connection : @raw_connection
conn.async_exec("SELECT 0 WHERE FALSE")
@raw_connection.async_exec("SELECT 0 WHERE FALSE")
end
end
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(StatementCaptureConnection)
Expand Down
Loading