Getting invalid connection option "prepared_statement" (PG::Error) #8784

Closed
SamSaffron opened this Issue Jan 6, 2013 · 11 comments

Projects

None yet

2 participants

@SamSaffron
Contributor

Just attempted to upgrade to Rails 4 and got:

/home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:703:in `initialize': invalid connection option "prepared_statement" (PG::Error)
  from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:703:in `new'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:703:in `connect'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:469:in `initialize'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:38:in `new'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:38:in `postgresql_connection'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `new_connection'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:456:in `checkout_new_connection'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:427:in `acquire_connection'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:364:in `block in checkout'
    from /home/sam/.rvm/rubies/ruby-1.9.3-p194-perf/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:363:in `checkout'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:273:in `block in connection'
    from /home/sam/.rvm/rubies/ruby-1.9.3-p194-perf/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:272:in `connection'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:551:in `retrieve_connection'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
    from /home/sam/.rvm/gems/ruby-1.9.3-p194-perf/bundler/gems/rails-9ee65aaaadfe/activerecord/lib/active_record/connection_handling.rb:53:in `connection'
    from /home/sam/Source/app/lib/site_setting_extension.rb:65:in `table_exists?'

pg 0.14.1 is in Gemfile.lock

@rafaelfranca
Member

What is you config/database.yml content?

@SamSaffron
Contributor
development:
  adapter: postgresql
  database: mydb
  host: localhost
  prepared_statement: false
  pool: 5
  timeout: 5000
@rafaelfranca
Member

The name of option is prepared_statements

@SamSaffron
Contributor

thanks !

@SamSaffron
Contributor

This does though raise an issue @rafaelfranca , in the past you could hang additional options off connection and now you can not so I think this should be re-opened.

For example for my multisite stuff I hang this off the connection:

host: site.com

in 4 its going to cause breakage, on one hand the change is good, cause it helps you catch typos, on the other hand it does not allow you to hang additional info off the connection you may want in other spots.

@rafaelfranca
Member

I didn't get your problem. Could you explain better what you can't do now?

@SamSaffron
Contributor

If my config is:

development:
  adapter: postgresql
  database: mydb
  host: localhost
  pool: 5
  timeout: 5000
  host_name: site.com

afaik in rails 3.2 it works, in 4 it fails.

I want an option in database.yml that is ignored by postgres I need to look at the code, but as far as I can tell from this bug, it seems there was some whitelisting of params that happened in 3.2 that no longer happens in 4.

@rafaelfranca
Member

I don't think we should support this, the database configuration is supposed to be used only to database configuration. If you want to store data I don't think this is the right place.

@SamSaffron
Contributor

I can work around this in my gem, but pool and adapter are already options that are not passed all the way into the pg provider and stripped out.

Is there a mechanism for my gem to expand on what I call "db configuration", for me I am saying the db "developement" is only for users that hit the host "site.com"

Additionally, this is a big breaking change, the error message really should be improved somehow if possible.

@rafaelfranca
Member

@SamSaffron I'm discussing to change this from backlist to whitelist, so you will not need to work around.

@rafaelfranca rafaelfranca reopened this Jan 7, 2013
@rafaelfranca rafaelfranca added a commit that closed this issue Jan 7, 2013
@rafaelfranca rafaelfranca Use whitelist to pass valid connection parameters to PGConn.
All the valids parameters for libpq are used.

See http://www.postgresql.org/docs/9.1/static/libpq-connect.html for the
full list

Fixes #8784
19b52d3
@SamSaffron
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment