From 9f5e0f512ae29b8fdc530d7fcb36fec01d8c9bc1 Mon Sep 17 00:00:00 2001 From: Aboobacker MK Date: Sun, 12 May 2024 22:00:54 +0530 Subject: [PATCH] Do not instantiate ActiveRecord model early Do not instantiate active record models before loading active record, as it can cause several side effects. Fixes https://github.com/doorkeeper-gem/doorkeeper/issues/1703 --- lib/doorkeeper/orm/active_record.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/doorkeeper/orm/active_record.rb b/lib/doorkeeper/orm/active_record.rb index 8cfa49e34..0bab10734 100644 --- a/lib/doorkeeper/orm/active_record.rb +++ b/lib/doorkeeper/orm/active_record.rb @@ -33,12 +33,14 @@ def self.run_hooks end def self.initialize_configured_associations - if Doorkeeper.config.enable_application_owner? - Doorkeeper.config.application_model.include ::Doorkeeper::Models::Ownership - end + ActiveSupport.on_load(:active_record) do + if Doorkeeper.config.enable_application_owner? + Doorkeeper.config.application_model.include ::Doorkeeper::Models::Ownership + end - Doorkeeper.config.access_grant_model.include ::Doorkeeper::Models::PolymorphicResourceOwner::ForAccessGrant - Doorkeeper.config.access_token_model.include ::Doorkeeper::Models::PolymorphicResourceOwner::ForAccessToken + Doorkeeper.config.access_grant_model.include ::Doorkeeper::Models::PolymorphicResourceOwner::ForAccessGrant + Doorkeeper.config.access_token_model.include ::Doorkeeper::Models::PolymorphicResourceOwner::ForAccessToken + end end end end