From ba877bd088db8ec276d10e14700ee0b87dcdb747 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 10 Jun 2021 18:42:59 +0200 Subject: [PATCH] Copy `config.active_record.*` again when `ActiveRecord::Base` is loaded Otherwise initializer files with `Rails.application.active_record.*` might break. --- activerecord/lib/active_record/core.rb | 4 ++++ activerecord/lib/active_record/migration.rb | 2 +- activerecord/lib/active_record/railtie.rb | 11 +++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 6490826503..36b9b9d87b 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -341,6 +341,10 @@ module ActiveRecord ActiveRecord.default_timezone end + def maintain_test_schema # :nodoc: + ActiveRecord.maintain_test_schema + end + def reading_role # :nodoc: ActiveSupport::Deprecation.warn(<<~MSG) ActiveRecord::Base.reading_role is deprecated and will be removed in Rails 7.0. diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 279461d892..bf26aaba5f 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -651,7 +651,7 @@ module ActiveRecord end def maintain_test_schema! #:nodoc: - if ActiveRecord.maintain_test_schema + if ActiveRecord::Base.maintain_test_schema suppress_messages { load_schema_if_pending! } end end diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index 8d24fa854d..5622a03bac 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -224,8 +224,15 @@ To keep using the current cache store, you can turn off cache versioning entirel configs.each do |k, v| next if k == :encryption setter = "#{k}=" - next if ActiveRecord.respond_to?(setter) - send(setter, v) + # Some existing initializers might rely on Active Record configuration + # being copied from the config object to their actual destination when + # `ActiveRecord::Base` is loaded. + # So to preserve backward compatibility we copy the config a second time. + if ActiveRecord.respond_to?(setter) + ActiveRecord.send(setter, v) + else + send(setter, v) + end end end end