#273 new
Nick Hoffman

Passing nil to paginate_by_* fails

Reported by Nick Hoffman | June 25th, 2009 @ 04:04 AM

Hi guys. I'm using:
* will_paginate 2.3.8 * Rails 2.3.2 * Ruby 1.8.7

I noticed that searching for a nil value using #paginate_by_* fails with an error.

First, it works with an integer:

?> Keyword.paginate_by_number_of_google_results 12_000, :page => 1
=> [#<Keyword id: 110472, keyword: "foo bar", estimated_cpc: #<BigDecimal:3a91138,'0.5342E2',8(8)>, created_at: "2009-06-25 01:30:11", updated_at: "2009-06-25 01:33:54", keyword_list_id: 35, hot: nil, number_of_google_results: 12000>]

However, it fails with nil:

Keyword.paginate_by_number_of_google_results nil, :page => 1
ActiveRecord::PreparedStatementInvalid: wrong number of bind variables (0 for 1) in: keywords.number_of_google_results is ?

    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2399:in `raise_if_bind_arity_mismatch'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2351:in `replace_bind_variables'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2342:in `sanitize_sql_array'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2235:in `sanitize_sql_orig'
    from /Users/nick/src/adsense_keywords/vendor/gems/ar-extensions-0.9.1/lib/ar-extensions/finders.rb:35:in `sanitize_sql'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1499:in `merge_conditions'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1497:in `each'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1497:in `merge_conditions'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2122:in `with_scope'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2116:in `each'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2116:in `with_scope'
    from (irb):119:in `inject'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2112:in `each'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2112:in `inject'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2112:in `with_scope'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_collection.rb:176:in `send'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_collection.rb:176:in `count'
    from /Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:223:in `wp_count'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2148:in `with_scope'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:206:in `send'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:206:in `with_scope'
    from /Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:233:in `wp_count'
    from /Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:85:in `paginate'
    from /Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/collection.rb:87:in `create'
    from /Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:76:in `paginate'
    from /Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:184:in `method_missing'
    from (irb):119</code>



The line above should be equivalent to this:

Keyword.paginate :conditions => {:number_of_google_results => nil}, :page => 1

Cheers,
Nick


Here's the output from running the will_paginate tests:

$ rake test
(in /Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8)
/opt/local/bin/ruby -I"/Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib" -I"/Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/test" "/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader.rb" "test/collection_test.rb" "test/finder_test.rb" "test/view_test.rb" 
using Rails gems
Loaded suite /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
Started
.......................................E......................................................
Finished in 0.897438 seconds.


1) Error: test_paginate_in_named_scope_on_hmt_association(FinderTest): ActiveRecord::StatementInvalid: SQLite3::SQLException: near "": syntax error: SELECT count("replies".) AS count_replies_all FROM "replies" INNER JOIN "topics" ON "replies".topic_id = "topics".id WHERE (((replies.created_at > '2009-06-24 21:49:20') AND (("topics".project_id = 1))) AND (("topics".project_id = 1)))

/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:157:in `execute_without_counting'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:402:in `catch_schema_changes'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:157:in `execute_without_counting'
/Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/test/lib/activerecord_test_connector.rb:69:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:305:in `select'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:13:in `select_one'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:19:in `select_value'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/calculations.rb:243:in `execute_simple_calculation'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/calculations.rb:134:in `calculate'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/calculations.rb:130:in `catch'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/calculations.rb:130:in `calculate'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/calculations.rb:48:in `count'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_collection.rb:176:in `count'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2148:in `with_scope'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_collection.rb:176:in `send'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_collection.rb:176:in `count'
/Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:223:in `wp_count'
/Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:235:in `call'
/Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:235:in `wp_count'
/Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:85:in `paginate'
/Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/collection.rb:87:in `create'
/Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:76:in `paginate'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:145:in `send'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:145:in `send'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:183:in `method_missing'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2148:in `with_scope'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:206:in `send'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:206:in `with_scope'
(__DELEGATION__):2:in `__send__'
(__DELEGATION__):2:in `with_scope'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:182:in `method_missing'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2148:in `with_scope'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:206:in `send'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:206:in `with_scope'
(__DELEGATION__):2:in `__send__'
(__DELEGATION__):2:in `with_scope'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:179:in `method_missing'
./test/finder_test.rb:248:in `test_paginate_in_named_scope_on_hmt_association'
/Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/test/lib/activerecord_test_case.rb:33:in `assert_queries'
./test/finder_test.rb:247:in `test_paginate_in_named_scope_on_hmt_association'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/testing/setup_and_teardown.rb:62:in `__send__'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/testing/setup_and_teardown.rb:62:in `run'
/Users/nick/src/adsense_keywords/vendor/gems/mislav-will_paginate-2.3.8/test/lib/activerecord_test_case.rb:22:in `run'



94 tests, 349 assertions, 0 failures, 1 errors rake aborted! Command failed with status (1): [/opt/local/bin/ruby -I"/Users/nick/src/ads...]
(See full trace by running task with --trace)

No comments found

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Everyone's favorite Ruby library for pagination of practically anything!

People watching this ticket

Pages