From 39204b8036d4cb83e121c60fb7b71ebe862522df Mon Sep 17 00:00:00 2001 From: Trevor Turk Date: Mon, 27 Jul 2026 11:04:40 -0500 Subject: [PATCH] Lease connections in DistinctValues instead of calling deprecated `connection` Bare `connection` resolves to the deprecated ActiveRecord::Base.connection, which raises under permanent_connection_checkout = :disallowed on Rails 8.1. Follows the connection_pool.with_connection pattern from #652. --- .../solid_queue/record/distinct_values.rb | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/models/solid_queue/record/distinct_values.rb b/app/models/solid_queue/record/distinct_values.rb index 59b2545c..5dcfc3db 100644 --- a/app/models/solid_queue/record/distinct_values.rb +++ b/app/models/solid_queue/record/distinct_values.rb @@ -19,23 +19,25 @@ def distinct_values_of(column) private def loose_index_scan_emulation_needed? - connection.adapter_name == "PostgreSQL" + connection_pool.with_connection { |connection| connection.adapter_name == "PostgreSQL" } end # Emulates a loose index scan, honoring the current scope (e.g. LIKE prefixes) # by building the anchor and the recursive step as scoped relations, whose # #to_sql inlines any bind parameters so they can be embedded in the raw CTE. def loose_distinct_via_recursive_cte(column) - col = connection.quote_column_name(column) + connection_pool.with_connection do |connection| + col = connection.quote_column_name(column) - connection.select_values(<<~SQL.squish) - WITH RECURSIVE t AS ( - (#{next_distinct_value(col, "#{col} IS NOT NULL")}) - UNION ALL - SELECT (#{next_distinct_value(col, "#{col} > t.#{col}")}) FROM t WHERE t.#{col} IS NOT NULL - ) - SELECT #{col} FROM t WHERE #{col} IS NOT NULL - SQL + connection.select_values(<<~SQL.squish) + WITH RECURSIVE t AS ( + (#{next_distinct_value(col, "#{col} IS NOT NULL")}) + UNION ALL + SELECT (#{next_distinct_value(col, "#{col} > t.#{col}")}) FROM t WHERE t.#{col} IS NOT NULL + ) + SELECT #{col} FROM t WHERE #{col} IS NOT NULL + SQL + end end # Smallest value of `col` within the current scope that matches `condition`.