Respect config.active_record.permanent_connection_checkout
#1570
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context:
config.active_record.permanent_connection_checkout
setting rails/rails#51349ActiveRecord::Base.with_connection
as a shortcut rails/rails#51083This PR addresses two things:
ActiveRecord::Base.connection
has been soft deprecated in favour of.lease_connection
, and applications can explicitly enable the deprecation by settingconfig.active_record.permanent_connection_checkout
to:deprecated
, or disallow its usage altogether by setting it to:disallowed
. In such cases the gem should not be using the deprecated method, but it would be good to avoid using it altogether so no further changes will be needed when it's hard deprecated..lease_connection
) in favour of theActiveRecord::ConnectionAdapters::ConnectionPool#with_connection
and newly addedActiveRecord::ConnectionHandling#with_connection
APIs. I think it would be good to support such applications by utilising these APIs where possible, instead of leasing a connection. I've ensured that this is true for all non-test code, but I don't know of a good way to prevent further usage (see this relevant comment). Also note thatActiveRecord::ConnectionHandling#with_connection
was added in 7.2, and since this gem currently supports 7.1 I've only relied on the connection pool method.