Skip to content

Drop legacy connection support#8883

Merged
tagliala merged 3 commits intomasterfrom
bugfix/8881-permanent-connection-cherrypick
Mar 6, 2026
Merged

Drop legacy connection support#8883
tagliala merged 3 commits intomasterfrom
bugfix/8881-permanent-connection-cherrypick

Conversation

@tagliala
Copy link
Contributor

@tagliala tagliala commented Dec 12, 2025

Replace all uses of ActiveRecord::Base.connection with
ActiveRecord::Base.with_connection, following Rails guidelines.

Direct connection usage is now dropped for Rails < 7.2, and
attempting to call .connection directly raises in Rails 8.x.
This aligns our codebase with current Rails recommendations and ensures
compatibility going forward.

Tests are updated to handle connection access correctly, running
some cases outside transactional fixtures to validate quoting and
order clause methods.

Close #8881

References:

@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.08%. Comparing base (1ef4ad0) to head (29c3596).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8883   +/-   ##
=======================================
  Coverage   99.08%   99.08%           
=======================================
  Files         139      139           
  Lines        4045     4046    +1     
=======================================
+ Hits         4008     4009    +1     
  Misses         37       37           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tagliala tagliala force-pushed the bugfix/8881-permanent-connection-cherrypick branch 2 times, most recently from 3761303 to 2a83d8d Compare December 13, 2025 10:44
@tagliala tagliala changed the title Bugfix/8881 permanent connection cherrypick Fix for :disallowed permanent connection checkout Dec 13, 2025
@tagliala tagliala changed the title Fix for :disallowed permanent connection checkout Fix :disallowed permanent connection checkout Dec 13, 2025
@tagliala tagliala requested a review from Copilot December 13, 2025 12:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses the Rails 7.2+ deprecation of ActiveRecord::Base.connection by updating the resource_quoted_column_name method to use the new with_connection API when available, preventing issues when permanent connection checkout is set to :disallowed.

Key Changes

  • Modified resource_quoted_column_name to use with_connection for Rails 7.2+ with fallback to .connection for older versions
  • Configured test environment to enforce :disallowed permanent connection checkout on Rails 7.2+
  • Added tests to verify the fix works correctly without transactional fixtures

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/active_admin/resource.rb Updated resource_quoted_column_name to use Rails 7.2+ with_connection API with backward compatibility
spec/support/rails_template.rb Added configuration to disallow permanent connection checkout in Rails 7.2+ test environment
spec/unit/resource_spec.rb Added test with transactional fixture opt-out to validate connection handling
spec/unit/order_clause_spec.rb Added transactional fixture opt-out to test that uses resource_quoted_column_name

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tagliala tagliala changed the title Fix :disallowed permanent connection checkout Use with_connection for column quoting on Rails 7.2+ Dec 13, 2025
@tagliala tagliala force-pushed the bugfix/8881-permanent-connection-cherrypick branch 2 times, most recently from a90e6a4 to 565802c Compare December 20, 2025 10:21
@tagliala tagliala force-pushed the bugfix/8881-permanent-connection-cherrypick branch 2 times, most recently from 6e7a0a2 to dbab39e Compare January 3, 2026 11:00
@tagliala tagliala marked this pull request as draft January 4, 2026 23:39
@tagliala
Copy link
Contributor Author

tagliala commented Jan 4, 2026

Converting back to draft because this PR will be affected by #8908

@javierjulio javierjulio added the do not merge A PR will have a failed check until this label is removed label Jan 6, 2026
@tagliala tagliala force-pushed the bugfix/8881-permanent-connection-cherrypick branch 2 times, most recently from a2cc3aa to 9bdd915 Compare January 6, 2026 10:24
@tagliala tagliala changed the title Use with_connection for column quoting on Rails 7.2+ Drop legacy connection support Jan 6, 2026
@tagliala tagliala marked this pull request as ready for review January 6, 2026 10:27
@tagliala tagliala removed the do not merge A PR will have a failed check until this label is removed label Jan 6, 2026
@tagliala tagliala requested a review from Copilot January 6, 2026 10:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tagliala tagliala force-pushed the bugfix/8881-permanent-connection-cherrypick branch 3 times, most recently from 11124da to 3bc360d Compare January 6, 2026 15:29
@tagliala tagliala force-pushed the bugfix/8881-permanent-connection-cherrypick branch from f0684cc to 0d692fc Compare January 28, 2026 09:12
@tagliala tagliala force-pushed the bugfix/8881-permanent-connection-cherrypick branch from 0d692fc to 6c25b4f Compare February 8, 2026 09:54
@tagliala tagliala force-pushed the bugfix/8881-permanent-connection-cherrypick branch from 6c25b4f to 381696c Compare February 17, 2026 18:46
@tagliala tagliala force-pushed the bugfix/8881-permanent-connection-cherrypick branch from c0376a4 to 563ca72 Compare March 5, 2026 08:55
@tagliala tagliala requested a review from Copilot March 6, 2026 09:24
@tagliala tagliala force-pushed the bugfix/8881-permanent-connection-cherrypick branch from 78c8d98 to e6e6273 Compare March 6, 2026 09:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Copy link
Contributor

Copilot AI commented Mar 6, 2026

@tagliala I've opened a new pull request, #8958, to work on those changes. Once the pull request is ready, I'll request review from you.

@tagliala
Copy link
Contributor Author

tagliala commented Mar 6, 2026

@javierjulio this change should also be good

Copy link
Member

@javierjulio javierjulio left a comment

Choose a reason for hiding this comment

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

Thanks! I didn't know what or where uses_transaction was coming from. I suggest adding the following method source link to the comment.

https://github.com/rails/rails/blob/v8.1.2/activerecord/lib/active_record/test_fixtures.rb#L100-L111


# Prevents automatically wrapping this test in a transaction. Check that we use the proper method to get a connection from the pool to quote the clause.
# We don't want to run the test using a leased connection https://github.com/rails/rails/blob/v7.2.3/activerecord/lib/active_record/test_fixtures.rb#L161
uses_transaction "#to_sql prepends table name"
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure this is working as intended? If so, all good with the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot why do we need, if we need, uses_transaction here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@javierjulio I'm not the original author of that change

Good catch, btw.

Maybe this has some effect on 7.1 or previously tested versions

I'm going to remove both those lines, because they do not change how the test is being performed in no versions of rails tested. I did expect a failure by removing those lines, but they didn't fail

When disallowed is set at configuration level, specs don't pass if we are not using with_connection properly

Example:

Failures:

  1) ActiveAdmin::Resource#resource_quoted_column_name should return quote argument
     Failure/Error: resource_class.connection.quote_column_name(column)
     
     ActiveRecord::ActiveRecordError:
       Called deprecated `ActiveRecord::Base.connection` method.
     
       Either use `with_connection` or `lease_connection`.

Copy link
Member

Choose a reason for hiding this comment

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

@tagliala ok great, sounds good, thanks again!

@tagliala tagliala marked this pull request as draft March 6, 2026 22:05
Copy link
Contributor

Copilot AI commented Mar 6, 2026

@tagliala I've opened a new pull request, #8962, to work on those changes. Once the pull request is ready, I'll request review from you.

davidrunger and others added 3 commits March 7, 2026 00:12
Replace all uses of `ActiveRecord::Base.connection` with
`ActiveRecord::Base.with_connection`, following Rails guidelines.

Direct connection usage is now dropped for Rails < 7.2, and
attempting to call .connection directly raises in Rails 8.x.
This aligns our codebase with current Rails recommendations and ensures
compatibility going forward.

Tests are updated to handle connection access correctly, running
some cases outside transactional fixtures to validate quoting and
order clause methods.

Close #8881

References:
- Rails PR: rails/rails#51349
- Connection Handling:
  https://github.com/rails/rails/blob/v7.2.1/activerecord/lib/active_record/connection_handling.rb#L259
…manent_connection_checkout = :disallowed` (#8958)

* Initial plan

* Fix spec to use lease_connection instead of connection

Replace ActiveRecord::Base.connection with ActiveRecord::Base.lease_connection
in the in_paginated_batches spec to be compatible with
permanent_connection_checkout = :disallowed set in test environment.

Co-authored-by: tagliala <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: tagliala <[email protected]>
…specs (#8962)

* Initial plan

* Remove unnecessary uses_transaction annotations from specs

The uses_transaction calls were added alongside with_connection in
resource_quoted_column_name, but are not needed because:

- with_connection is designed to work correctly within transactional tests
- quote_column_name is a pure string operation with no DB writes
- No special transaction handling is required for these tests

Co-authored-by: tagliala <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: tagliala <[email protected]>
@tagliala tagliala force-pushed the bugfix/8881-permanent-connection-cherrypick branch from b009716 to 29c3596 Compare March 6, 2026 23:12
@tagliala tagliala merged commit 8fb982f into master Mar 6, 2026
26 checks passed
@tagliala tagliala deleted the bugfix/8881-permanent-connection-cherrypick branch March 6, 2026 23:25
Copilot AI added a commit that referenced this pull request Mar 7, 2026
Use with_connection/lease_connection when available (Rails >= 7.2),
falling back to connection for older Rails versions. Conditionally
set permanent_connection_checkout config only for Rails >= 7.2.

This enables the backport to work on the 3-0-stable branch which
still supports Rails < 7.2.

Co-authored-by: tagliala <[email protected]>
Copilot AI added a commit that referenced this pull request Mar 8, 2026
Cherry-pick of e602ef7 applied to 3-0-stable with conflict resolution.
Uses with_connection/lease_connection when available (Rails >= 7.2),
falling back to connection for older Rails versions. Conditionally
sets permanent_connection_checkout config only for Rails >= 7.2.

Co-authored-by: tagliala <[email protected]>
tagliala added a commit that referenced this pull request Mar 8, 2026
Use with_connection/lease_connection when available (Rails >= 7.2),
falling back to connection for older Rails versions. Conditionally
set permanent_connection_checkout config only for Rails >= 7.2.

This enables the backport to work on the 3-0-stable branch which
still supports Rails < 7.2.

Co-authored-by: tagliala <[email protected]>
tagliala added a commit that referenced this pull request Mar 8, 2026
Use with_connection/lease_connection when available (Rails >= 7.2),
falling back to connection for older Rails versions. Conditionally
set permanent_connection_checkout config only for Rails >= 7.2.

This enables the backport to work on the 3-0-stable branch which
still supports Rails < 7.2.

Co-authored-by: tagliala <[email protected]>
tagliala added a commit that referenced this pull request Mar 8, 2026
Use with_connection/lease_connection when available (Rails >= 7.2),
falling back to connection for older Rails versions. Conditionally
set permanent_connection_checkout config only for Rails >= 7.2.

This enables the backport to work on the 3-0-stable branch which
still supports Rails < 7.2.

Co-authored-by: tagliala <[email protected]>
tagliala added a commit that referenced this pull request Mar 8, 2026
Backport PR #8883 with Rails version conditionals

Use with_connection/lease_connection when available (Rails >= 7.2),
falling back to connection for older Rails versions. Conditionally
set permanent_connection_checkout config only for Rails >= 7.2.

This enables the backport to work on the 3-0-stable branch which
still supports Rails < 7.2.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: tagliala <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ActiveAdmin does not work when permanent_connection_checkout is disallowed (v3 / v4, Rails >= 7.2)

6 participants