Skip to content

Commit cc9e209

Browse files
yahondaclaude
andcommitted
Prefer ActiveRecord.default_timezone over per-class accessor (rsim#234)
Calling ar_class.default_timezone on Rails 7.0/7.1 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 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 8.0+) and only fall back to the per-class accessor on pre-7.0 AR where the module-level one does not exist. The test in spec/plsql/schema_spec.rb already exercises the ActiveRecord.default_timezone path via respond_to?, so coverage is unchanged. Fixes rsim#234 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5ea974a commit cc9e209

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

lib/plsql/schema.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,15 @@ def default_timezone
9999
@original_schema.default_timezone
100100
else
101101
@default_timezone ||
102-
# Use ActiveRecord default_timezone when ActiveRecord connection is used,
103-
# preferring the connection's activerecord_class so a subclass override
104-
# (available in AR < 8.0) is honored before falling back to the
105-
# module-level accessor (AR 7.0+; the only one in AR 8.0+).
106-
(@connection && (ar_class = @connection.activerecord_class) &&
107-
(ar_class.respond_to?(:default_timezone) ? ar_class.default_timezone : ActiveRecord.default_timezone)) ||
102+
# Use ActiveRecord default_timezone when ActiveRecord connection is used.
103+
# Prefer the module-level accessor (AR 7.0+; the only one in AR 8.0+) so
104+
# that AR 7.0/7.1's deprecation warning for ActiveRecord::Base.default_timezone
105+
# is not emitted. Fall back to the per-class accessor only on pre-7.0 AR,
106+
# where ActiveRecord.default_timezone does not exist.
107+
(@connection && @connection.activerecord_class &&
108+
(ActiveRecord.respond_to?(:default_timezone) ?
109+
ActiveRecord.default_timezone :
110+
@connection.activerecord_class.default_timezone)) ||
108111
# default to local timezone
109112
:local
110113
end

0 commit comments

Comments
 (0)