-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doorkeeper is loading ActiveRecord too early #1703
Comments
tachyons
pushed a commit
to tachyons/doorkeeper
that referenced
this issue
May 12, 2024
Do not instantiate active record models before loading active record, as it can cause several side effects. Fixes doorkeeper-gem#1703
I've opened a PR to address this issue here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to reproduce
We found a weird behavior as we were upgrading Rails (7.0 => 7.1). When upgrading Rails, it generates a file called
config/initializers/new_framework_defaults.rb
where it sets a bunch ofRails.application.config.x.y = :something
in preparation for changing Rails defaults to the latest version.We noticed that some of these configs, especially the ones in
config.active_record.X
did not take hold. Meaning, they did not change the behavior of ActiveRecord. We dug into this further and found out that this happens when gem loads ActiveRecord too early. Here's a Rails issue describing the problem: rails/rails#50133. There's even work (in Rails) towards warning when this happens: rails/rails#46047For Doorkeeper, specifically, we traced it down to here:
doorkeeper/lib/doorkeeper/config.rb
Lines 440 to 442 in 1cc7145
Calling
access_token_model
will constantize the configured class and essentially loads an autoloaded model that lives insideapp/models/..
within the application. The problem is that this method is invoked very early in the setup phase of the doorkeeper gem:=> https://github.com/doorkeeper-gem/doorkeeper/blob/main/lib/doorkeeper/orm/active_record.rb#L41
from https://github.com/doorkeeper-gem/doorkeeper/blob/main/lib/doorkeeper.rb#L160-L172
from https://github.com/doorkeeper-gem/doorkeeper/blob/main/lib/doorkeeper/engine.rb#L23-L25
I've created a repo to help illustrate the problem. The README has the information.
https://github.com/ngan/doorkeeper-activerecord-load-issue
The text was updated successfully, but these errors were encountered: