thiagopradi / octopus

Database Sharding for ActiveRecord
2.53k stars 505 forks source link

Octopus crashes when calling unprepared_statement #374

Open vincent-pochet opened 8 years ago

vincent-pochet commented 8 years ago

Hi there,

I have fully replicated Postgres Master-Slave databases.

Octopus generates errors when somewhere in a Rails model I use connection.unprepared_statement

Let's say for example I have the following method: (Not really useful here but it's just an example ;))

def self.default
  connection.unprepared_statement do
    find_by(default: true)
  end
end

I get the following error :

ActiveRecord::StatementInvalid: 
ERROR: bind message supplies 1 parameters, but prepared statement "a97" requires 0

…/gems/ar-octopus-0.8.6/lib/octopus/abstract_adapter.rb:  15:in `instrument'
…/ruby/2.2.0/gems/ar-octopus-0.8.6/lib/octopus/proxy.rb: 479:in `block in send_queries_to_slave'
…/ruby/2.2.0/gems/ar-octopus-0.8.6/lib/octopus/proxy.rb: 509:in `using_shard'
…/ruby/2.2.0/gems/ar-octopus-0.8.6/lib/octopus/proxy.rb: 478:in `send_queries_to_slave'
…/ruby/2.2.0/gems/ar-octopus-0.8.6/lib/octopus/proxy.rb: 449:in `send_queries_to_selected_slave'
…/ruby/2.2.0/gems/ar-octopus-0.8.6/lib/octopus/proxy.rb: 301:in `method_missing'
…efy/releases/20160512074322/app/models/organization.rb:  31:in `block in default'
…/ruby/2.2.0/gems/ar-octopus-0.8.6/lib/octopus/proxy.rb: 303:in `method_missing'
…efy/releases/20160512074322/app/models/organization.rb:  30:in `default'

It seems that the connection proxy does not correctly delegates the unprepared_statement call to the database adapter.

Thank you for your help!

Pluto1010 commented 7 years ago

Did you solve this?

vincent-pochet commented 7 years ago

Unfortunately no... Not sure if it is still an issue as I switch to something else