Skip to content

Commit 85ebf8b

Browse files
committed
Emit a warning when pg gem < 1.6.0 is used with PostgreSQL 18+
Split from rails#55282 This commit emits a warning when `pg` gem < 1.6.0 is used with PostgreSQL 18+ to prevent compatibility issues of PG::Connection#cancel. PostgreSQL 18 (scheduled for release around September/October 2025) changes the format of the cancel request key , which causes PG::Connection#cancel to fail with pg gem 1.5.9 and below. This issue is already addressed in ged/ruby-pg#614 and the fix is included in pg gem v1.6.0 (currently released as v1.6.0.rc2). Instead of requiring pg gem 1.6+ for all users when raising minimum supported PostgreSQL version to 10 discussed at rails#55282 , warnings are only shown to PostgreSQL 18+ + pg gem ≤ 1.5.9 users actually affected by the PG::Connection#cancel behavior. Also skip the failing test if pg gem version < 1.6.0 and PostgreSQL version is 18+. ``` $ bundle info pg * pg (1.5.9) Summary: Pg is the Ruby interface to the PostgreSQL RDBMS Homepage: https://github.com/ged/ruby-pg Documentation: http://deveiate.org/code/pg Source Code: https://github.com/ged/ruby-pg Changelog: https://github.com/ged/ruby-pg/blob/master/History.md Path: /home/yahonda/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/pg-1.5.9 Reverse Dependencies: queue_classic (4.0.0) depends on pg (>= 1.1, < 2.0) $ $ ARCONN=postgresql bin/test test/cases/adapters/postgresql/transaction_test.rb -n test_raises_Interrupt_when_canceling_statement_via_interrupt Using postgresql Run options: -n test_raises_Interrupt_when_canceling_statement_via_interrupt --seed 17678 F Failure: ActiveRecord::PostgresqlTransactionTest#test_raises_Interrupt_when_canceling_statement_via_interrupt [test/cases/adapters/postgresql/transaction_test.rb:199]: Expected 10.014372003 to be < 5. bin/test test/cases/adapters/postgresql/transaction_test.rb:183 Finished in 10.067954s, 0.0993 runs/s, 0.1987 assertions/s. 1 runs, 2 assertions, 1 failures, 0 errors, 0 skips ```
1 parent d7cc945 commit 85ebf8b

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Emit a warning for pg gem < 1.6.0 when using PostgreSQL 18+
2+
3+
*Yasuo Honda*
4+
15
* Fix `#merge` with `#or` or `#and` and a mixture of attributes and SQL strings resulting in an incorrect query.
26

37
```ruby

activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@ def check_version # :nodoc:
666666
if database_version < 9_03_00 # < 9.3
667667
raise "Your version of PostgreSQL (#{database_version}) is too old. Active Record supports PostgreSQL >= 9.3."
668668
end
669+
if database_version >= 18_00_00 && Gem::Version.new(PG::VERSION) < Gem::Version.new("1.6.0")
670+
warn "pg gem version #{PG::VERSION} is known to be incompatible with PostgreSQL 18+. Please upgrade to pg 1.6.0 or later."
671+
end
669672
end
670673

671674
class << self

activerecord/test/cases/adapters/postgresql/transaction_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ class Sample < ActiveRecord::Base
181181
end
182182

183183
test "raises Interrupt when canceling statement via interrupt" do
184+
if ActiveRecord::Base.lease_connection.database_version >= 18_00_00 && Gem::Version.new(PG::VERSION) < Gem::Version.new("1.6.0")
185+
skip "pg gem version #{PG::VERSION} is known to be incompatible with PostgreSQL 18+. "
186+
end
184187
start_time = Time.now
185188
thread = Thread.new do
186189
Sample.transaction do

0 commit comments

Comments
 (0)