1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Raise if connection_handlers is called in legacy_connection_handling

While we didn't need to deprecate any behavior when implementing
granular connection swapping it's not 100% clear to the person upgrading
that this needs to change when you switch off
`legacy_connection_handling`. The new version doesn't support
multiple handlers but before it wasn't raising an exception so it was
possible applications were still using it and hitting confusing errors.
This change ensures that if an application is using the new handling
that `connection_handlers` and `connection_handlers=` an exception will
be raised.
This commit is contained in:
eileencodes 2020-11-17 08:11:08 -05:00
parent 86a9c893ed
commit 777e6d95e4
No known key found for this signature in database
GPG key ID: BA5C575120BBE8DF
4 changed files with 15 additions and 5 deletions

View file

@ -166,10 +166,18 @@ module ActiveRecord
end end
def self.connection_handlers def self.connection_handlers
unless legacy_connection_handling
raise NotImplementedError, "The new connection handling does not support accessing multiple connection handlers."
end
@@connection_handlers ||= {} @@connection_handlers ||= {}
end end
def self.connection_handlers=(handlers) def self.connection_handlers=(handlers)
unless legacy_connection_handling
raise NotImplementedError, "The new connection handling does not setting support multiple connection handlers."
end
@@connection_handlers = handlers @@connection_handlers = handlers
end end

View file

@ -1521,8 +1521,8 @@ if current_adapter?(:SQLite3Adapter) && !in_memory_db?
def teardown def teardown
ActiveRecord::Base.configurations = @prev_configs ActiveRecord::Base.configurations = @prev_configs
ActiveRecord::Base.connection_handler = @old_handler ActiveRecord::Base.connection_handler = @old_handler
ActiveRecord::Base.legacy_connection_handling = false
clean_up_legacy_connection_handlers clean_up_legacy_connection_handlers
ActiveRecord::Base.legacy_connection_handling = false
end end
def test_uses_writing_connection_for_fixtures def test_uses_writing_connection_for_fixtures

View file

@ -695,8 +695,10 @@ class QueryCacheTest < ActiveRecord::TestCase
mw.call({}) mw.call({})
ensure ensure
clean_up_legacy_connection_handlers unless in_memory_db?
ActiveRecord::Base.legacy_connection_handling = old_value clean_up_legacy_connection_handlers
ActiveRecord::Base.legacy_connection_handling = old_value
end
end end
def test_clear_query_cache_is_called_on_all_connections def test_clear_query_cache_is_called_on_all_connections

View file

@ -54,10 +54,10 @@ class TestFixturesTest < ActiveRecord::TestCase
test_result = klass.new("test_run_successfuly").run test_result = klass.new("test_run_successfuly").run
assert_predicate(test_result, :passed?) assert_predicate(test_result, :passed?)
ensure ensure
ActiveRecord::Base.legacy_connection_handling = old_value
ActiveRecord::Base.connection_handler = old_handler
clean_up_legacy_connection_handlers clean_up_legacy_connection_handlers
ActiveRecord::Base.connection_handler = old_handler
FileUtils.rm_r(tmp_dir) FileUtils.rm_r(tmp_dir)
ActiveRecord::Base.legacy_connection_handling = old_value
end end
def test_doesnt_rely_on_active_support_test_case_specific_methods def test_doesnt_rely_on_active_support_test_case_specific_methods