Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad SQL creation from a Ransack.search object. #573

Closed
jasonm23 opened this issue Aug 17, 2015 · 32 comments
Closed

Bad SQL creation from a Ransack.search object. #573

jasonm23 opened this issue Aug 17, 2015 · 32 comments

Comments

@jasonm23
Copy link

Hi, I have a strange situation with Ransack (1.6.2)

Ransack::Search<class: User, base: Grouping <conditions: [Condition <attributes: ["email"], predicate: contains, values: ["jas"]>], combinator: and>>

is generating SQL:

"SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM \"users\" WHERE \"users\".\"deleted_at\" IS NULL AND (\"users\".\"email\" >> '---\n- jas\n') LIMIT 30 OFFSET 0) subquery_for_count"

Instead of

"SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM \"users\" WHERE \"users\".\"deleted_at\" IS NULL AND (\"users\".\"email\" iLIKE '%jas%') LIMIT 30 OFFSET 0) subquery_for_count"

Any ideas why this is happening?!? Thank you!

@jasonm23
Copy link
Author

I noticed that the Arel.ast that Ransack is generating is setting the attribute value for email as:

name="email">,
@val=["jas"]>>>]>],

instead of

name="email">,
@val="%jas%">>>]>],

But I couldn't track down where this was set, so far.

@jonatack
Copy link
Contributor

Can you please provide the information in the Contributing Guide, needed to try to reproduce your issue?

Have you tried using version 1.6.6 or the master branch?

@jasonm23
Copy link
Author

We have to do a diff on this feature Gemlock and the master, I assume this may be a Arel issue too

@jasonm23
Copy link
Author

I'll try the latest from master too

@jasonm23
Copy link
Author

No diff !!? (We have it working fine on the other branch.) so obviously same Ransack version.

As mentioned before, the Arel.ast is the first place we found the difference.

Hoped you may have seen a similar occurrence.

@jasonm23
Copy link
Author

Not that it makes any difference but this is from ActiveAdmin, but the Params to controller don't differ.

@jasonm23
Copy link
Author

Log for the request, including the stacktrace.

Started GET "/admin/users?utf8=%E2%9C%93&q%5Bemail_contains%5D=jas&commit=Filter&order=id_desc" for 127.0.0.1 at 2015-08-17 21:27:59 +0800
  ActiveRecord::SchemaMigration Load (0.3ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by Admin::UsersController#index as HTML
  Parameters: {"utf8"=>"✓", "q"=>{"email_contains"=>"jas"}, "commit"=>"Filter", "order"=>"id_desc"}
  User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."deleted_at" IS NULL AND "users"."id" = 333  ORDER BY "users"."id" ASC LIMIT 1  [["id", 333]]
  Role Load (0.2ms)  SELECT  "roles".* FROM "roles" WHERE "roles"."id" = 1 LIMIT 1  [["id", 1]]
   (1.5ms)  SELECT COUNT(count_column) FROM (SELECT  1 AS count_column FROM "users" WHERE "users"."deleted_at" IS NULL AND ("users"."email" >> '---
- jas
') LIMIT 30 OFFSET 0) subquery_for_count
PG::UndefinedFunction: ERROR:  operator does not exist: character varying >> unknown
LINE 1: ...RE "users"."deleted_at" IS NULL AND ("users"."email" >> '---
                                                                ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT COUNT(count_column) FROM (SELECT  1 AS count_column FROM "users" WHERE "users"."deleted_at" IS NULL AND ("users"."email" >> '---
- jas
') LIMIT 30 OFFSET 0) subquery_for_count
  Rendered /Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/app/views/active_admin/resource/index.html.arb (123.4ms)
Completed 500 Internal Server Error in 172ms
** [Airbrake] Notice was not sent due to configuration:
  Environment Monitored? false
  API key set? false
D, [2015-08-17T21:27:59.890947 #82349] DEBUG -- : [Rollbar] Reporting exception: PG::UndefinedFunction: ERROR:  operator does not exist: character varying >> unknown
LINE 1: ...RE "users"."deleted_at" IS NULL AND ("users"."email" >> '---
                                                                ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT COUNT(count_column) FROM (SELECT  1 AS count_column FROM "users" WHERE "users"."deleted_at" IS NULL AND ("users"."email" >> '---
- jas
') LIMIT 30 OFFSET 0) subquery_for_count
D, [2015-08-17T21:27:59.891017 #82349] DEBUG -- : [Rollbar] Exception not reported because Rollbar is disabled

ActiveRecord::StatementInvalid - PG::UndefinedFunction: ERROR:  operator does not exist: character varying >> unknown
LINE 1: ...RE "users"."deleted_at" IS NULL AND ("users"."email" >> '---
                                                                ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT COUNT(count_column) FROM (SELECT  1 AS count_column FROM "users" WHERE "users"."deleted_at" IS NULL AND ("users"."email" >> '---
- jas
') LIMIT 30 OFFSET 0) subquery_for_count:
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract_adapter.rb:455:in `translate_exception_class'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract_adapter.rb:468:in `rescue in log'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `exec_no_cache'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:584:in `execute_and_clear'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql/database_statements.rb:160:in `exec_query'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:336:in `select'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `block in select_all'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/query_cache.rb:83:in `cache_sql'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `select_all'
  activerecord (4.2.0) lib/active_record/relation/calculations.rb:264:in `execute_simple_calculation'
  activerecord (4.2.0) lib/active_record/relation/calculations.rb:221:in `perform_calculation'
  activerecord (4.2.0) lib/active_record/relation/calculations.rb:127:in `calculate'
  activerecord (4.2.0) lib/active_record/relation/calculations.rb:42:in `count'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/helpers/collection.rb:9:in `collection_size'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/helpers/collection.rb:13:in `collection_is_empty?'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/index.rb:45:in `items_in_collection?'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/index.rb:49:in `build_collection'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/index.rb:28:in `block in main_content'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
  arbre (1.0.2) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:14:in `batch_action_form'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/index.rb:36:in `wrap_with_batch_action_form'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/index.rb:26:in `main_content'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/base.rb:87:in `block (2 levels) in build_main_content_wrapper'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
  arbre (1.0.2) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:14:in `div'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/base.rb:86:in `block in build_main_content_wrapper'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
  arbre (1.0.2) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:14:in `div'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/base.rb:85:in `build_main_content_wrapper'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/base.rb:71:in `block in build_page_content'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
  arbre (1.0.2) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:14:in `div'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/base.rb:70:in `build_page_content'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/base.rb:48:in `block (2 levels) in build_page'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
  arbre (1.0.2) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:14:in `div'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/base.rb:44:in `block in build_page'
  arbre (1.0.2) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/base.rb:43:in `build_page'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/views/pages/base.rb:10:in `build'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:30:in `block in build_tag'
  arbre (1.0.2) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.2) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/app/views/active_admin/resource/index.html.arb:2:in `block in ___sers_neo__rvm_gems_ruby_______airdrilling_bundler_gems_active_admin__aef______d__app_views_active_admin_resource_index_html_arb___1845682948105804477_70354850399060'
  arbre (1.0.2) lib/arbre/context.rb:45:in `initialize'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/app/views/active_admin/resource/index.html.arb:1:in `___sers_neo__rvm_gems_ruby_______airdrilling_bundler_gems_active_admin__aef______d__app_views_active_admin_resource_index_html_arb___1845682948105804477_70354850399060'
  actionview (4.2.0) lib/action_view/template.rb:145:in `block in render'
  activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
  actionview (4.2.0) lib/action_view/template.rb:333:in `instrument'
  actionview (4.2.0) lib/action_view/template.rb:143:in `render'
  haml_coffee_assets (1.16.0) lib/haml_coffee_assets/rails/engine.rb:73:in `render'
  actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
  actionview (4.2.0) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
  activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
  actionview (4.2.0) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
  actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
  actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
  actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
  actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:14:in `render'
  actionview (4.2.0) lib/action_view/renderer/renderer.rb:42:in `render_template'
  actionview (4.2.0) lib/action_view/renderer/renderer.rb:23:in `render'
  actionview (4.2.0) lib/action_view/rendering.rb:100:in `_render_template'
  actionpack (4.2.0) lib/action_controller/metal/streaming.rb:217:in `_render_template'
  actionview (4.2.0) lib/action_view/rendering.rb:83:in `render_to_body'
  actionpack (4.2.0) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
  actionpack (4.2.0) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
  actionpack (4.2.0) lib/abstract_controller/rendering.rb:25:in `render'
  actionpack (4.2.0) lib/action_controller/metal/rendering.rb:16:in `render'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
  activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
   () Users/neo/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
  activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `ms'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
  activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:40:in `render'
  remotipart (1.2.1) lib/remotipart/render_overrides.rb:14:in `render_with_remotipart'
  actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
  responders (2.0.2) lib/action_controller/responder.rb:236:in `default_render'
  responders (2.0.2) lib/action_controller/responder.rb:170:in `to_html'
  responders (2.0.2) lib/responders/flash_responder.rb:107:in `to_html'
  responders (2.0.2) lib/action_controller/responder.rb:163:in `respond'
  responders (2.0.2) lib/action_controller/responder.rb:156:in `call'
  responders (2.0.2) lib/action_controller/respond_with.rb:203:in `respond_with'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/inherited_resources-54eb09943793/lib/inherited_resources/actions.rb:7:in `index'
   () Users/neo/.rvm/gems/ruby-2.2.2@airdrilling/bundler/gems/active_admin-7aef260921d4/lib/active_admin/resource_controller/streaming.rb:12:in `index'
  actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
  actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
  activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
  activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
  activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
  actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
  actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
  actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/rack/browser_monitoring.rb:23:in `traced_call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/rack/developer_mode.rb:56:in `traced_call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.6.4) lib/rack/etag.rb:24:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.6.4) lib/rack/head.rb:13:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  remotipart (1.2.1) lib/remotipart/middleware.rb:27:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  airbrake (4.1.0) lib/airbrake/rails/middleware.rb:13:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rollbar (1.3.1) lib/rollbar/middleware/rails/rollbar.rb:24:in `block in call'
  rollbar (1.3.1) lib/rollbar.rb:747:in `scoped'
  rollbar (1.3.1) lib/rollbar/middleware/rails/rollbar.rb:22:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  rollbar (1.3.1) lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  airbrake (4.1.0) lib/airbrake/user_informer.rb:16:in `_call'
  airbrake (4.1.0) lib/airbrake/user_informer.rb:12:in `call'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  railties (4.2.0) lib/rails/engine.rb:518:in `call'
  railties (4.2.0) lib/rails/application.rb:164:in `call'
  railties (4.2.0) lib/rails/railtie.rb:194:in `method_missing'
  newrelic_rpm (3.9.9.275) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.6.4) lib/rack/deflater.rb:35:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  thin (1.6.3) lib/thin/connection.rb:86:in `block in pre_process'
  thin (1.6.3) lib/thin/connection.rb:84:in `pre_process'
  thin (1.6.3) lib/thin/connection.rb:53:in `process'
  thin (1.6.3) lib/thin/connection.rb:39:in `receive_data'
  eventmachine (1.0.4) lib/eventmachine.rb:187:in `run'
  thin (1.6.3) lib/thin/backends/base.rb:73:in `start'
  thin (1.6.3) lib/thin/server.rb:162:in `start'
  rack (1.6.4) lib/rack/handler/thin.rb:19:in `run'
  rack (1.6.4) lib/rack/server.rb:286:in `start'
  railties (4.2.0) lib/rails/commands/server.rb:80:in `start'
  railties (4.2.0) lib/rails/commands/commands_tasks.rb:80:in `block in server'
  railties (4.2.0) lib/rails/commands/commands_tasks.rb:75:in `server'
  railties (4.2.0) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  railties (4.2.0) lib/rails/commands.rb:17:in `<top (required)>'
   () Users/neo/workspace/OpsManager/bin/rails:25:in `<top (required)>'
  spring (1.2.0) lib/spring/client/rails.rb:27:in `call'
  spring (1.2.0) lib/spring/client/command.rb:7:in `call'
  spring (1.2.0) lib/spring/client.rb:26:in `run'
  spring (1.2.0) bin/spring:48:in `<top (required)>'
  spring (1.2.0) lib/spring/binstub.rb:11:in `<top (required)>'
   () Users/neo/workspace/OpsManager/bin/spring:16:in `<top (required)>'
   () rails:3:in `<main>'



Started POST "/__better_errors/f4b027739c287fdc/variables" for 127.0.0.1 at 2015-08-17 21:27:59 +0800
  User Load (1.0ms)  SELECT "users".* FROM "users" WHERE "users"."deleted_at" IS NULL AND ("users"."email" >> '---
- jas
')  ORDER BY "users"."id" desc
PG::UndefinedFunction: ERROR:  operator does not exist: character varying >> unknown
LINE 1: ...RE "users"."deleted_at" IS NULL AND ("users"."email" >> '---
                                                                ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT "users".* FROM "users" WHERE "users"."deleted_at" IS NULL AND ("users"."email" >> '---
- jas
')  ORDER BY "users"."id" desc

@jasonm23
Copy link
Author

Updated to 1.6.6 (from git head)

@jasonm23
Copy link
Author

@jasonm23
Copy link
Author

Ok, this appears to be an issue with ActiveAdmin, closing.

@jasonm23 jasonm23 reopened this Aug 17, 2015
@jasonm23
Copy link
Author

activeadmin/activeadmin#4078 (comment)

May actually be a ransack issue.

@jonatack
Copy link
Contributor

OK, so Ransack 1.6.6 and I can guess from your stack trace that you are using Ruby 2.2.2. Other than that, could you please provide the information mentioned in the Ransack Contributing Guide to try to reproduce your issue? Version of Active Record? Code?

@jonatack
Copy link
Contributor

I've copied the relevant part of the Contributing Guide for you here:

Filing an issue

A bug is a demonstrable problem that is caused by the code in the repository. Good bug reports are extremely helpful! Please do not use the issue tracker for personal support requests.

Guidelines for bug reports:

Use the GitHub issue search — check if the issue has already been reported.

Check if the issue has been fixed — try to reproduce it using the master branch in the repository.

Isolate and report the problem — ideally create a reduced test case.

When filing an issue, please provide these details:

A comprehensive list of steps to reproduce the issue, or - far better - a failing spec.
The version (and branch) of Ransack and the versions of Rails, Ruby, and your operating system.
Any relevant stack traces ("Full trace" preferred).

Any issue that is open for 14 days without actionable information or activity will be marked as "stalled" and then closed. Stalled issues can be re-opened if the information requested is provided.

@jasonm23
Copy link
Author

Code

[1] pry(main)> User.ransack(email_contains: "jas").result

Schema entry for users.email

t.string   "email",                   limit: 255, default: "",    null: false

Active Record version (4.2.0)

@jonatack
Copy link
Contributor

Works for me (Ransack master, Rails master, Ruby 2.2.2, PostgreSQL 9.4.1):

∴ bin/rails console
Loading development environment (Rails 5.0.0.alpha)

[1] pry(main)> User.ransack(email_cont: "jas").result.to_sql
=> "SELECT \"users\".* FROM \"users\" WHERE (\"users\".\"email\" ILIKE '%jas%')"

@timoschilling
Copy link
Contributor

Some background informations:

  • He uses ActiveAdmin, which uses Ransack
  • ActiveAdmin has a 'alias' from *_contains to *_cont, defined here, maybe this is the problem
  • He says that email_cont works, but email_contains not

I think the ActiveAdmin alias is the problem.

@jonatack
Copy link
Contributor

Thanks @timoschilling! Closing for now until further info shows this to be in Ransack.

@jasonm23
Copy link
Author

Thanks @timoschilling

FYI db is Postgresql

@timoschilling
Copy link
Contributor

@jonatack is there a clean way to make predicate aliases?

@jasonm23
Copy link
Author

Note that ActiveAdmin is configuring Ransack as follows.

Ransack.configure do |config|
  {'contains'=>'cont', 'starts_with'=>'start', 'ends_with'=>'end'}.each do |old,current|
    config.add_predicate old, Ransack::Constants::DERIVED_PREDICATES.detect{ |q, _| q == current }[1]
  end

  {'equals'=>'eq', 'greater_than'=>'gt', 'less_than'=>'lt'}.each do |old,current|
    config.add_predicate old, arel_predicate: current
  end
end

@timoschilling
Copy link
Contributor

@jasonm23 I know about that code, but it seams that it don't work in your case.

@jonatack
Copy link
Contributor

Is 'contains' the only one not working?

@timoschilling
Copy link
Contributor

I don't know, which is working by him.

The alias in ActiveAdmin exist since ~ 2 Years and we had never a problem like this.

@jonatack
Copy link
Contributor

Unless you or others can reproduce it, it may not be a bug.

@jasonm23
Copy link
Author

Contains is the only one building a weird SQL statement.

Equals, starts with and ends with work as expected.

@jasonm23
Copy link
Author

#573 (comment) note this, I would think it would be the biggest indicator of the cause? No?

Why would it be generating an array instead of the ILIKE usable string?

@timoschilling
Copy link
Contributor

@jasonm23 maybe you can give me or @jonatack access to your app or you can build a test app to reproduce this problem.

@jonatack
Copy link
Contributor

I don't use ActiveAdmin but a gist that allows Timo to run and reproduce
the issue would be useful.

On Wednesday, August 19, 2015, Timo Schilling [email protected]
wrote:

@jasonm23 https://github.com/jasonm23 maybe you can give me or @jonatack
https://github.com/jonatack access to your app or you can build a test
app to reproduce this problem.


Reply to this email directly or view it on GitHub
#573 (comment)
.

@timoschilling
Copy link
Contributor

@jasonm23 have you tried different versions of ActiveAdmin, Ransack, ActiveRecord and Postgre

@jasonm23
Copy link
Author

Unfortunately I cannot grant you guys access to the production app at this time. If you have any ideas, feed them to this thread.

Given that adding the filter: [:cont] option argument to your filter method @timoschilling, fixes the problem for me, I'm not really hurting from this.

If I were you, I'd want to know what was going wrong. Of course if it works for me is good enough for you, so be it.

@jasonm23
Copy link
Author

@timoschilling as you can see at the head of this issue. I tried different versions of both ActiveAdmin and Ransack when the problem surfaced.

I will put together a test app at some point, so that there's a test case. I would recommend keeping this in mind. but not to be concerned about it for now, since my app is functional with the work-around you gave me.

Obviously it's not happening to many people, but personally I like to know the cause. No doubt you would also like to know where the problem lies.

@jonatack
Copy link
Contributor

If your issue is not reproducible because you don't provide the information, it is not up to anyone else to go on a wild-goose chase of "guess what he may have done to have a problem." No one has time for that. Please respect the maintainers time.

On Wednesday, August 19, 2015, JasonM23 [email protected] wrote:

Unfortunately I cannot grant you guys access to the production app at this
time. If you have any ideas, feed them to this thread.

Given that adding the filter: [:cont] option argument to your filter
method @timoschilling https://github.com/timoschilling, fixes the
problem for me, I'm not really hurting from this.

If I were you, I'd want to know what was going wrong. Of course if it
works for me
is good enough for you, so be it.


Reply to this email directly or view it on GitHub
#573 (comment)
.

@activerecord-hackery activerecord-hackery locked and limited conversation to collaborators Aug 19, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants