We are planning the migration to Rails 7.2.2.1 (we currently run on 7.1.5.1).
We have noticed some errors during the CI run while querying with binding variable on integer column.
For example :
# Loading development environment (Rails 7.2.2.1)
FulfillmentZone.where("fulfillment_zones.maximum_zone_quantity >= :quantity", quantity: 15.0).to_a
FulfillmentZone Load (0.9ms) SELECT "fulfillment_zones".* FROM "fulfillment_zones" WHERE (fulfillment_zones.maximum_zone_quantity >= $1) [[nil, 15.0]]
ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: invalid input syntax for type integer: "15.0" (ActiveRecord::StatementInvalid)
CONTEXT: unnamed portal parameter $1 = '...'
from /Users/jlamarque/.rbenv/versions/3.3.7/lib/ruby/gems/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:912:in `exec_prepared'
Caused by PG::InvalidTextRepresentation: ERROR: invalid input syntax for type integer: "15.0"
CONTEXT: unnamed portal parameter $1 = '...'
from /Users/jlamarque/.rbenv/versions/3.3.7/lib/ruby/gems/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:912:in `exec_prepared'
The same query does not raise in 7.1.5.1 :
# Loading development environment (Rails 7.1.5.1)
FulfillmentZone.where("fulfillment_zones.maximum_zone_quantity >= :quantity", quantity: 15.0).to_a
FulfillmentZone Load (1.4ms) SELECT "fulfillment_zones".* FROM "fulfillment_zones" WHERE (fulfillment_zones.maximum_zone_quantity >= 15.0)
#=> [#<FulfillmentZone:0x00000001293d0ea8 id: 1, fulfillment_service_id: 1, name: "France", deleted_at: nil, created_at: Wed, 18 Sep 2024 12:06:57.819485000 CEST +02:00, updated_at: Wed, 18 Sep 2024 12:06:57.819485000 CEST +02:00, maximum_zone_quantity: 100>,
#<FulfillmentZone:0x0000000129218c00 id: 3, fulfillment_service_id: 3, name: "FRANCE", deleted_at: nil, created_at: Tue, 31 Dec 2024 09:32:23.843419000 CET +01:00, updated_at: Tue, 31 Dec 2024 09:32:23.843419000 CET +01:00, maximum_zone_quantity: 100>]
Any ideas ?
I investigated inside postgresql adaptor libs of activerecord (ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting) and noticed that the result of casting was returned by abstract quoting module (method type_cast). In the case of a numeric value, there is no casting, the value is returned unchanged, raising an invalid statement after.