Do not instantiate ActiveRecord model early#1708
Closed
tachyons wants to merge 1 commit intodoorkeeper-gem:mainfrom
Closed
Do not instantiate ActiveRecord model early#1708tachyons wants to merge 1 commit intodoorkeeper-gem:mainfrom
tachyons wants to merge 1 commit intodoorkeeper-gem:mainfrom
Conversation
Do not instantiate active record models before loading active record, as it can cause several side effects. Fixes doorkeeper-gem#1703
Member
|
I remember we already had such hook and it also lead to a lot of issues, unfortunately. I believe we can find them in the issues section |
nbulaj
approved these changes
Jun 2, 2024
Member
nbulaj
left a comment
There was a problem hiding this comment.
Well, let's try to use AS hooks once again 🤞
Member
|
Can you please add a changelog entry? |
Author
|
I checked the old issues and found that active support hooks caused issues
for STI loading. So I wanted to add tests for that before
proceeding further. But I haven't got time for that yet.
…On Mon, 3 Jun, 2024, 12:39 am Nikita Bulai, ***@***.***> wrote:
Can you please add a changelog entry?
—
Reply to this email directly, view it on GitHub
<#1708 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXYAEE6QU6RAQX7NQWN2PLZFNUVFAVCNFSM6AAAAABHS56NPWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBTHE4DSOJRGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Member
|
Hello @tachyons . maybe any updates on that? 👁️ |
55728
added a commit
to 55728/doorkeeper
that referenced
this pull request
Mar 25, 2026
Wrap `initialize_configured_associations` body in `ActiveSupport.on_load(:active_record)` to prevent Doorkeeper from instantiating ActiveRecord models too early during the Rails boot process. When Doorkeeper calls `constantize` on model class names (e.g. `access_token_model`, `application_model`) inside `config.to_prepare`, it can trigger early loading of ActiveRecord before `config.active_record.*` settings have been applied. This causes framework defaults (set in `new_framework_defaults.rb` during Rails upgrades) to be silently ignored. This change defers the model loading until ActiveRecord is fully initialized, which: - Fixes `config.active_record.*` settings being ignored (Rails 7.0→7.1 upgrade scenario reported in doorkeeper-gem#1703) - Aligns with the pattern recommended by Rails core (rails/rails#50133, rails/rails#46047) - Preserves STI subclass support (verified with dedicated tests) Fixes doorkeeper-gem#1703 Based on the approach from doorkeeper-gem#1708 by @tachyons, with the addition of CHANGELOG entry and STI-related tests as requested by @nbulaj.
55728
added a commit
to 55728/doorkeeper
that referenced
this pull request
Mar 26, 2026
Wrap `initialize_configured_associations` body in `ActiveSupport.on_load(:active_record)` to prevent Doorkeeper from instantiating ActiveRecord models too early during the Rails boot process. When Doorkeeper calls `constantize` on model class names (e.g. `access_token_model`, `application_model`) inside `config.to_prepare`, it can trigger early loading of ActiveRecord before `config.active_record.*` settings have been applied. This causes framework defaults (set in `new_framework_defaults.rb` during Rails upgrades) to be silently ignored. This change defers the model loading until ActiveRecord is fully initialized, which: - Fixes `config.active_record.*` settings being ignored (Rails 7.0→7.1 upgrade scenario reported in doorkeeper-gem#1703) - Aligns with the pattern recommended by Rails core (rails/rails#50133, rails/rails#46047) - Preserves STI subclass support (verified with dedicated tests) Fixes doorkeeper-gem#1703 Based on the approach from doorkeeper-gem#1708 by @tachyons, with the addition of CHANGELOG entry and STI-related tests as requested by @nbulaj.
Member
|
We merged #1804 so I believe we can close this one. Thanks! |
Author
|
Thanks @nbulaj |
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
Do not instantiate active record models before loading active record, as it can cause several side effects.
Fixes #1703