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

Issue with PostgreSQL adapter: ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR #14

Closed
bbonamin opened this issue Nov 26, 2015 · 7 comments
Labels

Comments

@bbonamin
Copy link

Hello!

Thank you for open sourcing this gem, think it's a brilliant idea. I've been able to give it a try with sqlite3, but I haven't had much luck making it work with PostgreSQL. (Latest Rails 4.2 and Ruby 2.2.3)

Given a User model, with a attribute of name, if one is present in the database; when I run Polo.explore(User, 1), I get the following stack trace:

irb(main):001:0> Polo.explore(User, 1)
  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1  [["id", 1]]
  User Load (0.7ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1
  User Load (1.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1
ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR:  bind message supplies 0 parameters, but prepared statement "" requires 1
: SELECT "users".* FROM "users" WHERE "users"."id" = $1
    from /Users/bcb/.gem/ruby/2.2.3/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `block in exec_no_cache'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `exec_no_cache'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:584:in `execute_and_clear'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:160:in `exec_query'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:355:in `select'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activerecord-4.2.5/lib/active_record/querying.rb:39:in `find_by_sql'
    from /Users/bcb/.gem/ruby/2.2.3/gems/polo-0.1.0/lib/polo/translator.rb:24:in `block in instances'
    from /Users/bcb/.gem/ruby/2.2.3/gems/polo-0.1.0/lib/polo/translator.rb:23:in `each'
    from /Users/bcb/.gem/ruby/2.2.3/gems/polo-0.1.0/lib/polo/translator.rb:23:in `flat_map'
    from /Users/bcb/.gem/ruby/2.2.3/gems/polo-0.1.0/lib/polo/translator.rb:23:in `instances'
... 5 levels...
    from /Users/bcb/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
    from /Users/bcb/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Users/bcb/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/bcb/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
    from /Users/bcb/code/polo_rails_test/bin/rails:9:in `<top (required)>'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/bcb/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
    from /Users/bcb/.rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/bcb/.rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

Here's a sample application that exhibits this behavior: https://github.com/bbonamin/polo_rails_test

Let me know if I can be of any help :) To be honest I'm kind of lost on where to go an fix this, but apparently it's related to the fact that PostgreSQL validates prepared statements. rails/rails#20077

@nettofarah
Copy link
Contributor

Hi, @bbonamin. Thank you for reporting this!
Tbh, PG support is something I haven't look into much. But I know some people are working on it.

@derencius is working on it though.
Maybe he'll be able to give us some insight.
https://github.com/derencius/polo/pull/1

@nettofarah nettofarah added the bug label Nov 26, 2015
@bbonamin
Copy link
Author

This is great! Thanks. I didn't even think of checking the open pull requests 😖 !
I'll follow that PR with interest.

@jlerpscher
Copy link

Same issue here, I'll also follow that PR :)
Thanks

@nettofarah
Copy link
Contributor

Here's the PR, folks!
#20

I'd love for y'all to provide some feedback.

@nettofarah
Copy link
Contributor

solved!

@bbonamin
Copy link
Author

bbonamin commented Dec 4, 2015

Thanks @nettofarah and @derencius 💯 👍 💯 !

@nettofarah
Copy link
Contributor

@bbonamin, @derencius, @jlerpscher mind helping us with the survey on #19?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants