ransack icon indicating copy to clipboard operation
ransack copied to clipboard

Upgraded to rails 4.2 and get `unsupported: String`

Open mhenrixon opened this issue 3 years ago • 0 comments

I'm sorry this ain't pretty, but I wanted to check in on something.

def search
  @search ||= begin
                base = products.widget_filter(booking_widget_request?).includes(:editables)
                with_search = if params["search"]
                  base.published_text_search(params)
                else
                  base
                end
                if params[:q]
                  with_ransack = with_search.ransack(params[:q])
                  with_ransack.sorts = ["position asc", "editables_name asc"] if with_ransack.sorts.empty?
                  with_ransack.result
                else
                  with_search
                end
              end
end

This is the changed code; the old code didn't check for if params[:q] and just ran .ransack(params[:q]) even if the param was nil or empty.

It was working great on rails 4.1, but in rails 4.2, I get: unsupported: String

Backtrace

RuntimeError:
       unsupported: String
     # /usr/local/bundle/gems/arel-6.0.4/lib/arel/visitors/to_sql.rb:736:in `unsupported'
     # /usr/local/bundle/gems/arel-6.0.4/lib/arel/visitors/reduce.rb:13:in `visit'
     # /usr/local/bundle/gems/arel-6.0.4/lib/arel/visitors/to_sql.rb:757:in `visit_Arel_Nodes_InfixOperation'
     # /usr/local/bundle/gems/arel-6.0.4/lib/arel/visitors/reduce.rb:13:in `visit'
     # /usr/local/bundle/gems/arel-6.0.4/lib/arel/visitors/to_sql.rb:446:in `visit_Arel_Nodes_Ascending'
     # /usr/local/bundle/gems/arel-6.0.4/lib/arel/visitors/reduce.rb:13:in `visit'
     # /usr/local/bundle/gems/arel-6.0.4/lib/arel/visitors/reduce.rb:7:in `accept'
     # /usr/local/bundle/gems/arel-6.0.4/lib/arel/nodes/node.rb:48:in `to_sql'
     # /usr/local/bundle/gems/activerecord-4.2.11.3/lib/active_record/connection_adapters/postgresql/schema_statements.rb:585:in `block in columns_for_distinct'
     # /usr/local/bundle/gems/activerecord-4.2.11.3/lib/active_record/connection_adapters/postgresql/schema_statements.rb:583:in `map'
     # /usr/local/bundle/gems/activerecord-4.2.11.3/lib/active_record/connection_adapters/postgresql/schema_statements.rb:583:in `columns_for_distinct'
     # /usr/local/bundle/gems/activerecord-4.2.11.3/lib/active_record/relation/finder_methods.rb:395:in `limited_ids_for'
     # /usr/local/bundle/gems/activerecord-4.2.11.3/lib/active_record/relation/finder_methods.rb:387:in `apply_join_dependency'
     # /usr/local/bundle/gems/activerecord-4.2.11.3/lib/active_record/relation/finder_methods.rb:347:in `find_with_associations'
     # /usr/local/bundle/gems/activerecord-4.2.11.3/lib/active_record/relation.rb:639:in `exec_queries'
     # /usr/local/bundle/gems/activerecord-4.2.11.3/lib/active_record/relation.rb:515:in `load'
     # /usr/local/bundle/gems/activerecord-4.2.11.3/lib/active_record/relation.rb:243:in `to_a'
     # /usr/local/bundle/gems/will_paginate-3.3.1/lib/will_paginate/active_record.rb:127:in `block in to_a'
     # /usr/local/bundle/gems/will_paginate-3.3.1/lib/will_paginate/collection.rb:96:in `create'
     # /usr/local/bundle/gems/will_paginate-3.3.1/lib/will_paginate/active_record.rb:126:in `to_a'
     # /usr/local/bundle/gems/activerecord-4.2.11.3/lib/active_record/relation.rb:630:in `inspect'
     # ./app/controllers/public/booking/base_controller.rb:55:in `p'
     # ./app/controllers/public/booking/base_controller.rb:55:in `to_response'
     # ./app/controllers/public/booking/products_controller.rb:12:in `block (2 levels) in index'
     # /usr/local/bundle/gems/actionpack-4.2.11.3/lib/action_controller/metal/mime_responds.rb:217:in `respond_to'
     # ./app/controllers/public/booking/products_controller.rb:5:in `index'

I made sure to upgrade ransack before rails to make sure I can easily track down any potential issues. Had some trouble with our custom use of pg_search:

sanitized_term = unsanitized_term.gsub(DISALLOWED_TSQUERY_CHARACTERS, " ")
    term_sql       = Arel.sql(normalize(connection.quote(sanitized_term)))
    tsquery        = tsquery_expression(term_sql, negated: false, prefix: true)

    Arel::Nodes::NamedFunction.new(
      "to_tsquery",
      [Arel::Nodes.build_quoted(dictionary), tsquery]
    ).to_sql

It now expects whatever build_quoted returns as a parameter. There might be some scenarios that are still not compatible with rails 4.2?

Running ransack 1.8.10, which is the latest rails 4.2 compatible version?

mhenrixon avatar Jan 11 '23 19:01 mhenrixon