Commit b1b48aa2 authored by Yorick Peterse's avatar Yorick Peterse

Add connection fallback to ActiveRecordProxy

As observed in https://gitlab.com/gitlab-org/gitlab/-/issues/341584,
prepending ActiveRecordProxy before setting up the proxy may result in
database queries being run that expect a connection. To work around
this, ActiveRecordProxy now falls back to retrieving a regular
connection when a proxy isn't available yet.

Changelog: fixed
parent 029f872a
......@@ -7,7 +7,7 @@ module Gitlab
# "connection" method.
module ActiveRecordProxy
def connection
::Gitlab::Database::LoadBalancing.proxy
::Gitlab::Database::LoadBalancing.proxy || super
end
end
end
......
......@@ -16,5 +16,12 @@ RSpec.describe Gitlab::Database::LoadBalancing::ActiveRecordProxy do
expect(dummy.new.connection).to eq(proxy)
end
it 'returns a connection when no proxy is present' do
allow(Gitlab::Database::LoadBalancing).to receive(:proxy).and_return(nil)
expect(ActiveRecord::Base.connection)
.to eq(ActiveRecord::Base.retrieve_connection)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment