Error using Rails insert/upsert methods (`insert_all` and similar) with load balancing enabled
Summary
When load balancing is enabled, the standard ActiveRecord connection object is replaced with our own Gitlab::Database::LoadBalancing::ConnectionProxy
. This uses method_missing
to pass any messages we haven't overridden through to a normal connection object.
This does not work with Rails InsertAll
, which causes method(:quote_column_name)
to be called on the proxy connection, circumventing the method_missing
logic.
Steps to reproduce
(How one can reproduce the issue - this is very important)
Example Project
(If possible, please create an example project here on GitLab.com that exhibits the problematic behavior, and link to it here in the bug report)
(If you are using an older version of GitLab, this will also determine whether the bug is fixed in a more recent version)
What is the current bug behavior?
(What actually happens)
What is the expected correct behavior?
(What you should see instead)
Relevant logs and/or screenshots
NameError:
undefined method `quote_column_name' for class `Gitlab::Database::LoadBalancing::ConnectionProxy'
# ./ee/lib/gitlab/database/load_balancing/connection_proxy.rb:79:in `block in write_using_load_balancer'
# ./ee/lib/gitlab/database/load_balancing/load_balancer.rb:84:in `block in read_write'
# ./ee/lib/gitlab/database/load_balancing/load_balancer.rb:134:in `retry_with_backoff'
# ./ee/lib/gitlab/database/load_balancing/load_balancer.rb:83:in `read_write'
# ./ee/lib/gitlab/database/load_balancing/connection_proxy.rb:73:in `write_using_load_balancer'
# ./ee/lib/gitlab/database/load_balancing/connection_proxy.rb:53:in `method_missing'
Possible fixes
(If you can, link to the line of code that might be responsible for the problem)