Prefer ActiveRecord.default_timezone over per-class accessor#268
Merged
yahonda merged 1 commit intorsim:masterfrom Apr 14, 2026
Merged
Prefer ActiveRecord.default_timezone over per-class accessor#268yahonda merged 1 commit intorsim:masterfrom
yahonda merged 1 commit intorsim:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates PLSQL::Schema#default_timezone to prefer the Rails 7+ module-level ActiveRecord.default_timezone API (avoiding the Rails 7.0/7.1 deprecation warning from ActiveRecord::Base.default_timezone), with a fallback for older ActiveRecord versions.
Changes:
- Reordered timezone lookup in
PLSQL::Schema#default_timezoneto useActiveRecord.default_timezonefirst when available. - Added a regression spec to assert no
ActiveRecord::Base.default_timezonedeprecation warning is emitted on Rails versions that support the module-level accessor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
lib/plsql/schema.rb |
Prefer ActiveRecord.default_timezone to avoid Rails 7 deprecation warnings; keep fallback for older AR. |
spec/plsql/schema_spec.rb |
Add test coverage to ensure plsql.default_timezone does not emit the deprecated warning. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Calling `ar_class.default_timezone` on Rails 7.0.x prints DEPRECATION WARNING: ActiveRecord::Base.default_timezone is deprecated and will be removed in Rails 7.1. Use ActiveRecord.default_timezone instead. even though both accessors return the same value. The per-class accessor was introduced as a deprecated proxy in Rails 7.0 (rails/rails@c3f43075a3) and removed entirely in Rails 7.1 (rails/rails@96c9db1b48), so the warning only fires on Rails 7.0.x. Switch the order in PLSQL::Schema#default_timezone so that we ask the module-level ActiveRecord.default_timezone first when it is available (AR 7.0+) and only fall back to the per-class accessor on pre-7.0 AR where the module-level one does not exist. This silences the warning on Rails 7.0.x and is a no-op on Rails 7.1+ (where the per-class accessor was already gone) and on Rails <= 6.x (where the module-level accessor did not yet exist). Add a regression test that captures deprecator output while resolving plsql.default_timezone with `activerecord_class` set, and asserts that no warning mentioning default_timezone was raised. The existing ActiveRecord.default_timezone is captured before assignment and restored from the ensure block alongside the deprecator behavior so the test is order-independent. Verified by rsim#269 / rsim#271 that the test fails on AR 7.0 without this fix and passes on AR 7.1+ regardless. Fixes rsim#234 References: - rails/rails@c3f43075a3 (added the deprecated delegators in Rails 7.0) - rails/rails@96c9db1b48 (removed them in Rails 7.1) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
07a48a6 to
7cea354
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Calling
ar_class.default_timezoneon Rails 7.0.x printseven though both accessors return the same value.
Switch the order in
PLSQL::Schema#default_timezoneso that we ask themodule-level
ActiveRecord.default_timezonefirst when it is available(AR 7.0+, and the only accessor left in AR 7.1+) and only fall back to
the per-class accessor on pre-7.0 AR where the module-level one does
not exist.
Fixes #234
Affected Rails versions
plsql.activerecord_class.ActiveRecord::Base.default_timezoneaccessor was removed entirely in commit rails/rails@96c9db1 (March 2023). With it gone,ar_class.respond_to?(:default_timezone)returnsfalseand the existing fallback path inPLSQL::Schema#default_timezonealready usesActiveRecord.default_timezone— so 7.1/7.2/8.0 users were never seeing the warning. The fix still applies cleanly for them and is a no-op behavior-wise.ActiveRecord.default_timezonedoesn't exist; the per-class fallback continues to be used. No behavior change.Behavior change
On AR 7.0+, a user who set
MyModel.default_timezone = :utc(thedeprecated per-class API) and then
plsql.activerecord_class = MyModelpreviously had that per-class override honored. After this change the
module-level
ActiveRecord.default_timezoneis consulted instead andthe per-class override is ignored. This matches the direction Rails
itself is moving (AR 7.1 removed the per-class accessor entirely) and
silences the deprecation warning rather than emulating the deprecated
API.
Test plan
this fix (deprecation warning surfaces from
lib/plsql/schema.rb:107)and passes on AR 7.1+ with or without the fix (since the deprecated
accessor is no longer present).
test_gemfilesmatrix passes on AR 5.0 through AR 8.0.user code that configures
plsql.activerecord_class.🤖 Generated with Claude Code