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

Search breaks when updating to Rails 4.1 #10

Closed
O-I opened this issue Apr 29, 2014 · 9 comments
Closed

Search breaks when updating to Rails 4.1 #10

O-I opened this issue Apr 29, 2014 · 9 comments

Comments

@O-I
Copy link
Owner

O-I commented Apr 29, 2014

Rails 4.1, will_paginate, and pg_search seem to not want to play nicely with each other. See also this issue.

Here's what I get when I search for 'ruby'

Started GET "/favorites?utf8=%E2%9C%93&query=ruby&_=1398793557291" for 127.0.0.1 at 2014-04-29 13:46:05 -0400
Processing by FavoritesController#index as JS
  Parameters: {"utf8"=>"✓", "query"=>"ruby", "_"=>"1398793557291"}
   (1.1ms)  SELECT COUNT("favorites".*, ((ts_rank((setweight(to_tsvector('english', coalesce("favorites"."text"::text, '')), 'A') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_name"::text, '')), 'B') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_screen_name"::text, '')), 'C')), (to_tsquery('english', ''' ' || 'ruby' || ' ''')), 0))) AS pg_search_rank) FROM "favorites"  WHERE (((setweight(to_tsvector('english', coalesce("favorites"."text"::text, '')), 'A') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_name"::text, '')), 'B') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_screen_name"::text, '')), 'C')) @@ (to_tsquery('english', ''' ' || 'ruby' || ' '''))))
PG::SyntaxError: ERROR:  syntax error at or near "AS"
LINE 1: ...query('english', ''' ' || 'ruby' || ' ''')), 0))) AS pg_sear...
                                                             ^
: SELECT COUNT("favorites".*, ((ts_rank((setweight(to_tsvector('english', coalesce("favorites"."text"::text, '')), 'A') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_name"::text, '')), 'B') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_screen_name"::text, '')), 'C')), (to_tsquery('english', ''' ' || 'ruby' || ' ''')), 0))) AS pg_search_rank) FROM "favorites"  WHERE (((setweight(to_tsvector('english', coalesce("favorites"."text"::text, '')), 'A') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_name"::text, '')), 'B') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_screen_name"::text, '')), 'C')) @@ (to_tsquery('english', ''' ' || 'ruby' || ' '''))))
  Rendered favorites/index.js.erb (11.9ms)
Completed 500 Internal Server Error in 18ms

ActiveRecord::StatementInvalid - PG::SyntaxError: ERROR:  syntax error at or near "AS"
LINE 1: ...query('english', ''' ' || 'ruby' || ' ''')), 0))) AS pg_sear...
                                                             ^
: SELECT COUNT("favorites".*, ((ts_rank((setweight(to_tsvector('english', coalesce("favorites"."text"::text, '')), 'A') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_name"::text, '')), 'B') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_screen_name"::text, '')), 'C')), (to_tsquery('english', ''' ' || 'ruby' || ' ''')), 0))) AS pg_search_rank) FROM "favorites"  WHERE (((setweight(to_tsvector('english', coalesce("favorites"."text"::text, '')), 'A') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_name"::text, '')), 'B') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_screen_name"::text, '')), 'C')) @@ (to_tsquery('english', ''' ' || 'ruby' || ' ''')))):
  activerecord (4.1.0) lib/active_record/connection_adapters/abstract_adapter.rb:362:in `translate_exception_class'
  activerecord (4.1.0) lib/active_record/connection_adapters/abstract_adapter.rb:375:in `rescue in log'
  activerecord (4.1.0) lib/active_record/connection_adapters/abstract_adapter.rb:373:in `log'
  activerecord (4.1.0) lib/active_record/connection_adapters/postgresql_adapter.rb:815:in `exec_no_cache'
  activerecord (4.1.0) lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'
  activerecord (4.1.0) lib/active_record/connection_adapters/postgresql_adapter.rb:947:in `select'
  activerecord (4.1.0) lib/active_record/connection_adapters/abstract/database_statements.rb:31:in `select_all'
  activerecord (4.1.0) lib/active_record/connection_adapters/abstract/query_cache.rb:67:in `block in select_all'
  activerecord (4.1.0) lib/active_record/connection_adapters/abstract/query_cache.rb:82:in `cache_sql'
  activerecord (4.1.0) lib/active_record/connection_adapters/abstract/query_cache.rb:67:in `select_all'
  activerecord (4.1.0) lib/active_record/relation/calculations.rb:254:in `execute_simple_calculation'
  activerecord (4.1.0) lib/active_record/relation/calculations.rb:216:in `perform_calculation'
  activerecord (4.1.0) lib/active_record/relation/calculations.rb:111:in `calculate'
  activerecord (4.1.0) lib/active_record/relation/calculations.rb:26:in `count'
  will_paginate (3.0.5) lib/will_paginate/active_record.rb:90:in `count'
  will_paginate (3.0.5) lib/will_paginate/active_record.rb:88:in `count'
  will_paginate (3.0.5) lib/will_paginate/active_record.rb:106:in `empty?'
  app/views/favorites/index.js.erb:1:in `_app_views_favorites_index_js_erb__4569055898240115273_2158512780'
  actionview (4.1.0) lib/action_view/template.rb:145:in `block in render'
  activesupport (4.1.0) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.1.0) lib/active_support/notifications.rb:159:in `instrument'
  actionview (4.1.0) lib/action_view/template.rb:339:in `instrument'
  actionview (4.1.0) lib/action_view/template.rb:143:in `render'
  actionview (4.1.0) lib/action_view/renderer/template_renderer.rb:55:in `block (2 levels) in render_template'
  actionview (4.1.0) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  activesupport (4.1.0) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.1.0) lib/active_support/notifications.rb:159:in `instrument'
  actionview (4.1.0) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  actionview (4.1.0) lib/action_view/renderer/template_renderer.rb:54:in `block in render_template'
  actionview (4.1.0) lib/action_view/renderer/template_renderer.rb:62:in `render_with_layout'
  actionview (4.1.0) lib/action_view/renderer/template_renderer.rb:53:in `render_template'
  actionview (4.1.0) lib/action_view/renderer/template_renderer.rb:17:in `render'
  actionview (4.1.0) lib/action_view/renderer/renderer.rb:42:in `render_template'
  actionview (4.1.0) lib/action_view/renderer/renderer.rb:23:in `render'
  actionview (4.1.0) lib/action_view/rendering.rb:99:in `_render_template'
  actionpack (4.1.0) lib/action_controller/metal/streaming.rb:217:in `_render_template'
  actionview (4.1.0) lib/action_view/rendering.rb:82:in `render_to_body'
  actionpack (4.1.0) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
  actionpack (4.1.0) lib/action_controller/metal/renderers.rb:32:in `render_to_body'
  actionpack (4.1.0) lib/abstract_controller/rendering.rb:25:in `render'
  actionpack (4.1.0) lib/action_controller/metal/rendering.rb:16:in `render'
  actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
  activesupport (4.1.0) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
  /Users/Raevynheart/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
  activesupport (4.1.0) lib/active_support/core_ext/benchmark.rb:12:in `ms'
  actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
  actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
  activerecord (4.1.0) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
  actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:40:in `render'
  actionpack (4.1.0) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
  actionpack (4.1.0) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
  actionpack (4.1.0) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.1.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.1.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.1.0) lib/active_support/callbacks.rb:113:in `call'
  activesupport (4.1.0) lib/active_support/callbacks.rb:229:in `block in halting'
  activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.0) lib/active_support/callbacks.rb:86:in `run_callbacks'
  actionpack (4.1.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.1.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.1.0) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.1.0) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.1.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.1.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.1.0) lib/abstract_controller/base.rb:136:in `process'
  actionview (4.1.0) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.1.0) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.1.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.1.0) lib/action_controller/metal.rb:231:in `block in action'
  actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
  actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
  actionpack (4.1.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.1.0) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:676:in `call'
  newrelic_rpm (3.8.0.218) lib/new_relic/rack/error_collector.rb:55:in `call'
  newrelic_rpm (3.8.0.218) lib/new_relic/rack/agent_hooks.rb:32:in `call'
  newrelic_rpm (3.8.0.218) lib/new_relic/rack/browser_monitoring.rb:27:in `call'
  newrelic_rpm (3.8.0.218) lib/new_relic/rack/developer_mode.rb:45:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  actionpack (4.1.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.1.0) lib/action_dispatch/middleware/flash.rb:254:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.1.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.1.0) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
  activerecord (4.1.0) lib/active_record/migration.rb:380:in `call'
  actionpack (4.1.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.1.0) lib/active_support/callbacks.rb:82:in `run_callbacks'
  actionpack (4.1.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.1.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.1.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
  actionpack (4.1.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.1.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.0) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.0) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.0) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.0) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.1.0) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.1.0) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.0) lib/rails/engine.rb:514:in `call'
  railties (4.1.0) lib/rails/application.rb:144:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  thin (1.6.2) lib/thin/connection.rb:86:in `block in pre_process'
  thin (1.6.2) lib/thin/connection.rb:84:in `pre_process'
  thin (1.6.2) lib/thin/connection.rb:53:in `process'
  thin (1.6.2) lib/thin/connection.rb:39:in `receive_data'
  eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
  thin (1.6.2) lib/thin/backends/base.rb:73:in `start'
  thin (1.6.2) lib/thin/server.rb:162:in `start'
  rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
  rack (1.5.2) lib/rack/server.rb:264:in `start'
  railties (4.1.0) lib/rails/commands/server.rb:69:in `start'
  railties (4.1.0) lib/rails/commands/commands_tasks.rb:81:in `block in server'
  railties (4.1.0) lib/rails/commands/commands_tasks.rb:76:in `server'
  railties (4.1.0) lib/rails/commands/commands_tasks.rb:40:in `run_command!'
  railties (4.1.0) lib/rails/commands.rb:17:in `<top (required)>'
  bin/rails:4:in `<main>'

@O-I
Copy link
Owner Author

O-I commented Apr 29, 2014

I'm rolling back to Rails 4.0.4 for now.

@O-I
Copy link
Owner Author

O-I commented Apr 29, 2014

This is what searching for 'ruby' on Rails 4.0.4 generates in the console:

Started GET "/favorites?utf8=%E2%9C%93&query=ruby&_=1398795051849" for 127.0.0.1 at 2014-04-29 14:10:57 -0400
Processing by FavoritesController#index as JS
  Parameters: {"utf8"=>"✓", "query"=>"ruby", "_"=>"1398795051849"}
   (107.0ms)  SELECT COUNT(*) FROM "favorites" WHERE (((setweight(to_tsvector('english', coalesce("favorites"."text"::text, '')), 'A') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_name"::text, '')), 'B') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_screen_name"::text, '')), 'C')) @@ (to_tsquery('english', ''' ' || 'ruby' || ' '''))))
  Favorite Load (109.8ms)  SELECT "favorites".*, ((ts_rank((setweight(to_tsvector('english', coalesce("favorites"."text"::text, '')), 'A') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_name"::text, '')), 'B') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_screen_name"::text, '')), 'C')), (to_tsquery('english', ''' ' || 'ruby' || ' ''')), 0))) AS pg_search_rank FROM "favorites" WHERE (((setweight(to_tsvector('english', coalesce("favorites"."text"::text, '')), 'A') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_name"::text, '')), 'B') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_screen_name"::text, '')), 'C')) @@ (to_tsquery('english', ''' ' || 'ruby' || ' ''')))) ORDER BY pg_search_rank DESC, "favorites"."id" ASC, date_tweeted DESC LIMIT 25 OFFSET 0
  CACHE (0.0ms)  SELECT COUNT(*) FROM "favorites" WHERE (((setweight(to_tsvector('english', coalesce("favorites"."text"::text, '')), 'A') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_name"::text, '')), 'B') || setweight(to_tsvector('english', coalesce("favorites"."tweeter_screen_name"::text, '')), 'C')) @@ (to_tsquery('english', ''' ' || 'ruby' || ' '''))))
  Rendered favorites/_favorite.html.erb (18.5ms)
  Rendered favorites/index.js.erb (245.7ms)
Completed 200 OK in 253ms (Views: 34.3ms | ActiveRecord: 216.8ms)

@O-I
Copy link
Owner Author

O-I commented Apr 29, 2014

This seems to have been fixed with this pull request to will_paginate. It hasn't been merged yet, but it seems to work with Rails 4.1 when I test using this fork.

@O-I
Copy link
Owner Author

O-I commented May 5, 2014

Using nazgum's fork and Rails 4.1 for now.

@O-I O-I closed this as completed May 5, 2014
@O-I O-I reopened this May 6, 2014
@O-I
Copy link
Owner Author

O-I commented May 6, 2014

It turns out this is an issue with Rails that is supposedly solved by updating to 4.1.1. I have not been able to get this to work updating Rails, so will continue to use nazgum/will_paginate and keep this issue open until it is resolved.

@O-I O-I closed this as completed May 6, 2014
@O-I O-I reopened this May 6, 2014
@O-I
Copy link
Owner Author

O-I commented May 6, 2014

Apparently, Rails 4.1.1 is just security commits. So, looks like it'll be a while before this gets fixed.

@DazDotOne
Copy link

updated to Rails 4.1.2 and nazgums fork seems to be working.

4.1.2 doesn't fix the issue implicitly

@O-I
Copy link
Owner Author

O-I commented Jul 2, 2014

You are correct that Rails 4.1.2 doesn't fix this issue. nazgum's fork is a quick and dirty solution to get this to work — no tests added and not really suitable for real-world production use. Having said that, the fix to count with tests has been merged into the master branch of will_paginate. There has been no new gem release, though. You'd have to point to the master branch rather than using what is on Rubygems if you wanted to go that route.

@O-I
Copy link
Owner Author

O-I commented Jul 4, 2014

will_paginate 3.0.7 was just released. This fixes this issue.

@O-I O-I closed this as completed Jul 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants