Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure variables are set in case enlist_fixture_connections is called #42060

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions activerecord/lib/active_record/test_fixtures.rb
Expand Up @@ -111,12 +111,11 @@ def setup_fixtures(config = ActiveRecord::Base)
@fixture_connections = []
@@already_loaded_fixtures ||= {}
@connection_subscriber = nil
@legacy_saved_pool_configs = Hash.new { |hash, key| hash[key] = {} }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're making changes in here can you condition these or make one instance var? I don't want the legacy one available when we're not in legacy mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I kept the variables separate but made sure they were only defined and used on their respective connection handling logic since it's more explicit and would allow us to just remove the legacy connection block once we remove that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileencodes I had to revert the change to condition these variables since it looks like the tests call out a setup and teardown with different values causing the variable to load values for legacy and then attempt to tear down non-legacy values and vice-versa.

This caused the failures seen here

Error:
--

BasePreventWritesTest::BasePreventWritesLegacyTest#test_preventing_writes_with_multiple_handlers:
--
  | NoMethodError: undefined method `[]' for nil:NilClass
  | /rails/activerecord/lib/active_record/test_fixtures.rb:209:in `block (2 levels) in setup_shared_connection_pool'

Using the same variable causes the same issue.

@saved_pool_configs = Hash.new { |hash, key| hash[key] = {} }

# Load fixtures once and begin transaction.
if run_in_transaction?
@legacy_saved_pool_configs = Hash.new { |hash, key| hash[key] = {} }
@saved_pool_configs = Hash.new { |hash, key| hash[key] = {} }

if @@already_loaded_fixtures[self.class]
@loaded_fixtures = @@already_loaded_fixtures[self.class]
else
Expand Down