Skip to content

Prefer ActiveRecord.default_timezone over per-class accessor#268

Merged
yahonda merged 1 commit intorsim:masterfrom
yahonda:fix-issue-234-default-timezone
Apr 14, 2026
Merged

Prefer ActiveRecord.default_timezone over per-class accessor#268
yahonda merged 1 commit intorsim:masterfrom
yahonda:fix-issue-234-default-timezone

Conversation

@yahonda
Copy link
Copy Markdown
Collaborator

@yahonda yahonda commented Apr 14, 2026

Summary

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.

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 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

  • Rails 7.0.x — emits the deprecation warning in user code that configures plsql.activerecord_class.
  • Rails 7.1+ — the per-class ActiveRecord::Base.default_timezone accessor was removed entirely in commit rails/rails@96c9db1 (March 2023). With it gone, ar_class.respond_to?(:default_timezone) returns false and the existing fallback path in PLSQL::Schema#default_timezone already uses ActiveRecord.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.
  • Rails ≤ 6.xActiveRecord.default_timezone doesn'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 (the
deprecated per-class API) and then plsql.activerecord_class = MyModel
previously had that per-class override honored. After this change the
module-level ActiveRecord.default_timezone is consulted instead and
the 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

🤖 Generated with Claude Code

Copy link
Copy Markdown

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 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_timezone to use ActiveRecord.default_timezone first when available.
  • Added a regression spec to assert no ActiveRecord::Base.default_timezone deprecation 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.

Comment thread lib/plsql/schema.rb
Comment thread spec/plsql/schema_spec.rb
Copy link
Copy Markdown

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 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>
@yahonda yahonda force-pushed the fix-issue-234-default-timezone branch from 07a48a6 to 7cea354 Compare April 14, 2026 02:12
@yahonda yahonda merged commit 66bf4b1 into rsim:master Apr 14, 2026
21 checks passed
@yahonda yahonda deleted the fix-issue-234-default-timezone branch April 14, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ActiveRecord::Base.default_timezone is deprecated and will be removed in Rails 7.1

2 participants