Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
3761303 to
2a83d8d
Compare
:disallowed permanent connection checkout
:disallowed permanent connection checkout:disallowed permanent connection checkout
There was a problem hiding this comment.
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_nameto usewith_connectionfor Rails 7.2+ with fallback to.connectionfor older versions - Configured test environment to enforce
:disallowedpermanent 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.
:disallowed permanent connection checkoutwith_connection for column quoting on Rails 7.2+
a90e6a4 to
565802c
Compare
6e7a0a2 to
dbab39e
Compare
|
Converting back to draft because this PR will be affected by #8908 |
a2cc3aa to
9bdd915
Compare
with_connection for column quoting on Rails 7.2+There was a problem hiding this comment.
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.
11124da to
3bc360d
Compare
f0684cc to
0d692fc
Compare
0d692fc to
6c25b4f
Compare
6c25b4f to
381696c
Compare
c0376a4 to
563ca72
Compare
78c8d98 to
e6e6273
Compare
|
@javierjulio this change should also be good |
There was a problem hiding this comment.
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
spec/unit/order_clause_spec.rb
Outdated
|
|
||
| # 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" |
There was a problem hiding this comment.
Are we sure this is working as intended? If so, all good with the changes.
There was a problem hiding this comment.
@copilot why do we need, if we need, uses_transaction here?
There was a problem hiding this comment.
@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`.
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]>
b009716 to
29c3596
Compare
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]>
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]>
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]>
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]>
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]>
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]>
Replace all uses of
ActiveRecord::Base.connectionwithActiveRecord::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:
config.active_record.permanent_connection_checkoutsetting rails/rails#51349https://github.com/rails/rails/blob/v7.2.1/activerecord/lib/active_record/connection_handling.rb#L259