From d6f3ad7ce7066b8815b4bda4a1e843b2c72c2ad3 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Tue, 10 May 2016 23:00:33 -0400 Subject: Make sure we reset the connection_specification_name on remove_connection When calling `remove_connection` on a model, we delete the pool so we also need to reset the `connection_specification_name` so it will fallback to the parent. This was the current behavior before rails 5, which will fallback to the parent connection pool. [fixes #24959] Special thanks to @jrafanie for working with me on this fix. --- activerecord/lib/active_record/connection_handling.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/connection_handling.rb') diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb index a628ee4dbd..0a69ad2c0e 100644 --- a/activerecord/lib/active_record/connection_handling.rb +++ b/activerecord/lib/active_record/connection_handling.rb @@ -95,7 +95,7 @@ module ActiveRecord # Return the specification name from the current class or its parent. def connection_specification_name - unless defined?(@connection_specification_name) + if !defined?(@connection_specification_name) || @connection_specification_name.nil? @connection_specification_name = self == Base ? "primary" : superclass.connection_specification_name end @connection_specification_name @@ -133,6 +133,13 @@ module ActiveRecord end def remove_connection(name = connection_specification_name) + # if removing a connection that have a pool, we reset the + # connection_specification_name so it will use the parent + # pool. + if connection_handler.retrieve_connection_pool(name) + self.connection_specification_name = nil + end + connection_handler.remove_connection(name) end -- cgit v1.2.3