You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Rails 6.0.3 And Ransack 2.3.2 this passes. But when you upgrade to Ransack 2.4.0 (and later), with or without Rails 6.1.4, the IN (('major 1', '')) changes to IN ('major 1', '') causing the error:
ActiveRecord::StatementInvalid:
PG::FeatureNotSupported: ERROR: input of anonymous composite types is not implemented
LINE 1: ...OALESCE(TRIM("degrees"."concentration"), '')) IN ('major 1',...
Here is the bug reproduction (just changing versions):
# frozen_string_literal: trueunlessFile.exist?('Gemfile')File.write('Gemfile',%q( source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem 'rails', github: 'rails/rails', tag: 'v6.0.3' gem 'ransack', '~> 2.4.2' gem 'sqlite3' ))system'bundle install'endrequire'bundler'Bundler.setup(:default)require'active_record'require'minitest/autorun'require'logger'require'ransack'# This connection will do for database-independent bug reports.ActiveRecord::Base.establish_connection(adapter: 'sqlite3',database: ':memory:')ActiveRecord::Base.logger=Logger.new($stdout)# Display versions.message="Running test case with Ruby #{RUBY_VERSION}, Active Record #{ ::ActiveRecord::VERSION::STRING}, Arel #{Arel::VERSION} and #{ ::ActiveRecord::Base.connection.adapter_name}"line='=' * message.lengthputsline,message,lineActiveRecord::Schema.definedocreate_table:degrees,force: truedo |t|
t.string:concentrationt.string:majorendend# ModelclassDegree < ActiveRecord::Baseransacker:major_concentration,formatter: lambda{ |tuples|
major,concentration=JSON.parse(tuples)Arel::Nodes::Grouping.new([Arel::Nodes.build_quoted(major),Arel::Nodes.build_quoted(concentration)])}do |_parent|
degrees=Degree.arel_tableArel::Nodes::Grouping.new(%i[majorconcentration].mapdo |field|
Arel::Nodes::NamedFunction.new('COALESCE',[Arel::Nodes::NamedFunction.new('TRIM',[degrees[field]]),Arel::Nodes.build_quoted('')])end)endend# Bug TestclassBugTest < Minitest::Testdeftest_ransackransack_hash=ActiveSupport::HashWithIndifferentAccess.new({m: 'and',g: [ActiveSupport::HashWithIndifferentAccess.new({major_concentration_in: ['["major 1", ""]']})]})sql=Degree.ransack(ransack_hash).result.to_sqlputssqlassert_equal"SELECT \"degrees\".* FROM \"degrees\" WHERE (COALESCE(TRIM(\"degrees\".\"major\"), ''), COALESCE(TRIM(\"degrees\".\"concentration\"), '')) IN (('major 1', ''))",sqlendend
The breaking change was introduced in commit 93615c3 and the method causing this issue is method casted_array?.
In Rails 6.0.3 And Ransack 2.3.2 this passes. But when you upgrade to Ransack 2.4.0 (and later), with or without Rails 6.1.4, the
IN (('major 1', ''))
changes toIN ('major 1', '')
causing the error:Here is the bug reproduction (just changing versions):
The breaking change was introduced in commit 93615c3 and the method causing this issue is method
casted_array?
.The Arel generated changes from
to
Any help/fix would be appreciated as this is a blocker in an app Rails upgrade at work.
The text was updated successfully, but these errors were encountered: