Skip to content

Deprecation warning when using Rails 7.2 #340

@martingregoire

Description

@martingregoire

Issue

We are currently upgrading our application to Rails 7.2, including an upgrade of the data_migrate gem from 9.4.2 to 11.0.0.

After these upgrades we see the following deprecation warning when starting the Rails server:

DEPRECATION WARNING: ActiveRecord::ConnectionAdapters::ConnectionPool#connection is deprecated
and will be removed in Rails 8.0. Use #lease_connection instead.
 (called from <main> at bin/rails:4)

.../gems/data_migrate-11.0.0/lib/data_migrate/database_tasks.rb:27:in `block in with_temporary_connection'
.../gems/data_migrate-11.0.0/lib/data_migrate/database_tasks.rb:43:in `with_temporary_pool'
.../gems/data_migrate-11.0.0/lib/data_migrate/database_tasks.rb:26:in `with_temporary_connection'
.../gems/activerecord-7.2.1/lib/active_record/tasks/database_tasks.rb:473:in `block in load_schema_current'
.../gems/activerecord-7.2.1/lib/active_record/tasks/database_tasks.rb:595:in `block (2 levels) in each_current_configuration'
.../gems/activerecord-7.2.1/lib/active_record/tasks/database_tasks.rb:592:in `each'
.../gems/activerecord-7.2.1/lib/active_record/tasks/database_tasks.rb:592:in `block in each_current_configuration'
.../gems/activerecord-7.2.1/lib/active_record/tasks/database_tasks.rb:603:in `each'
.../gems/activerecord-7.2.1/lib/active_record/tasks/database_tasks.rb:603:in `each_current_environment'
.../gems/activerecord-7.2.1/lib/active_record/tasks/database_tasks.rb:591:in `each_current_configuration'
.../gems/activerecord-7.2.1/lib/active_record/tasks/database_tasks.rb:472:in `load_schema_current'
.../gems/data_migrate-11.0.0/tasks/databases.rake:248:in `block (3 levels) in <main>'

The warning is caused by this method call:

def with_temporary_connection(db_config) # :nodoc:
with_temporary_pool(db_config) do |pool|
yield pool.connection
end
end

Reference

I found the following similar code in the Rails repository. They are using pool.with_connection(&block):

https://github.com/rails/rails/blob/97169912f197eee6e76fafb091113bddf624aa67/activerecord/lib/active_record/tasks/database_tasks.rb#L520

Please see the following commit, where this change was introduced and the deprecation was added:
rails/rails@7263da5

Maybe the deprecation warning can be fixed in data_migrate in a similar way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions