doorkeeper-gem / doorkeeper

Doorkeeper is an OAuth 2 provider for Ruby on Rails / Grape.
https://doorkeeper.gitbook.io/guides/
MIT License
5.27k stars 1.06k forks source link

NameError: uninitialized constant error during rake assets:precompile using doorkeeper 5.6.3 #1651

Open denisahearn opened 1 year ago

denisahearn commented 1 year ago

Steps to reproduce

The following initializer and custom Doorkeeper::AccessToken model class work fine when using doorkeeper 5.6.2 within a Rails 7 app, but after upgrading to doorkeeper 5.6.3, a NameError: uninitialized constant ApiSession error happens while running RAILS_ENV=production rake assets:precompile --trace.

This same error happens with the latest version of doorkeeper (5.6.6) as well.

# config/initializers/doorkeeper.rb

Doorkeeper.configure do
  orm :active_record
  access_token_class 'ApiSession'
  ...
end

# app/models/api_session.rb

class ApiSession < Doorkeeper::AccessToken
  ...
end

Expected behavior

The rake assets:precompile command should work for doorkeeper 5.6.3 just like it does for 5.6.2

Actual behavior

Running RAILS_ENV=production rake assets:precompile --trace with doorkeeper 5.6.3 results in the following error:

 > RAILS_ENV=production rake assets:precompile --trace
#41 8.698 ** Invoke assets:precompile (first_time)
#41 8.698 ** Invoke assets:environment (first_time)
#41 8.698 ** Execute assets:environment
#41 8.698 ** Invoke environment (first_time)
#41 8.698 ** Execute environment
#41 9.153 rake aborted!
#41 9.153 NameError: uninitialized constant ApiSession
#41 9.153 /usr/local/bundle/gems/activesupport-7.0.4.3/lib/active_support/inflector/methods.rb:280:in `constantize'
#41 9.153 /usr/local/bundle/gems/activesupport-7.0.4.3/lib/active_support/core_ext/string/inflections.rb:74:in `constantize'
#41 9.153 /usr/local/bundle/gems/doorkeeper-5.6.3/lib/doorkeeper/config.rb:425:in `access_token_model'
#41 9.153 /usr/local/bundle/gems/doorkeeper-5.6.3/lib/doorkeeper/orm/active_record.rb:41:in `initialize_configured_associations'
#41 9.153 /usr/local/bundle/gems/doorkeeper-5.6.3/lib/doorkeeper/orm/active_record.rb:32:in `run_hooks'
#41 9.153 /usr/local/bundle/gems/doorkeeper-openid_connect-1.8.5/lib/doorkeeper/openid_connect/orm/active_record.rb:13:in `run_hooks'
#41 9.153 /usr/local/bundle/gems/doorkeeper-5.6.3/lib/doorkeeper.rb:164:in `run_orm_hooks'
#41 9.153 /usr/local/bundle/gems/doorkeeper-5.6.3/lib/doorkeeper.rb:140:in `setup'
#41 9.153 /usr/local/bundle/gems/doorkeeper-5.6.3/lib/doorkeeper.rb:122:in `configure'
#41 9.153 /cloudvault/config/initializers/doorkeeper.rb:3:in `<top (required)>'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/engine.rb:667:in `load'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/engine.rb:667:in `block in load_config_initializer'
#41 9.153 /usr/local/bundle/gems/activesupport-7.0.4.3/lib/active_support/notifications.rb:208:in `instrument'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/engine.rb:666:in `load_config_initializer'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/engine.rb:620:in `block (2 levels) in <class:Engine>'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/engine.rb:619:in `each'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/engine.rb:619:in `block in <class:Engine>'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `instance_exec'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `run'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/initializable.rb:61:in `block in run_initializers'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:228:in `block in tsort_each'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:431:in `each_strongly_connected_component_from'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/initializable.rb:50:in `each'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/initializable.rb:50:in `tsort_each_child'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:415:in `call'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:415:in `each_strongly_connected_component_from'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:349:in `block in each_strongly_connected_component'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:347:in `each'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:347:in `call'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:347:in `each_strongly_connected_component'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:226:in `tsort_each'
#41 9.153 /usr/local/lib/ruby/2.7.0/tsort.rb:205:in `tsort_each'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/initializable.rb:60:in `run_initializers'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/application.rb:372:in `initialize!'
#41 9.153 /cloudvault/config/environment.rb:8:in `<top (required)>'
#41 9.153 /usr/local/bundle/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
#41 9.153 /usr/local/bundle/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/application.rb:348:in `require_environment!'
#41 9.153 /usr/local/bundle/gems/railties-7.0.4.3/lib/rails/application.rb:511:in `block in run_tasks_blocks'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#41 9.153 /usr/local/bundle/gems/airbrake-13.0.3/lib/airbrake/rake.rb:17:in `execute'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#41 9.153 /usr/local/bundle/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#41 9.153 /usr/local/bundle/gems/airbrake-13.0.3/lib/airbrake/rake.rb:17:in `execute'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/application.rb:83:in `block in run'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/lib/rake/application.rb:80:in `run'
#41 9.153 /usr/local/bundle/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
#41 9.153 /usr/local/bundle/bin/rake:23:in `load'
#41 9.153 /usr/local/bundle/bin/rake:23:in `<main>'
#41 9.153 Tasks: TOP => environment

System configuration

You can help us to understand your problem if you will share some very useful information about your project environment (don't forget to remove any confidential data if it exists).

Doorkeeper initializer:

# config/initializers/doorkeeper.rb
Doorkeeper.configure do
  # Change the ORM that doorkeeper will use (needs plugins)
  orm :active_record

  access_token_class 'ApiSession'

  use_polymorphic_resource_owner

  # This block will be called to check whether the resource owner is authenticated or not.
  resource_owner_authenticator do
    current_user || begin
      session[:user_return_to] = request.fullpath
      Rails.logger.info("User return to: #{session[:user_return_to]}")

      if User.omniauth_providers.include?(params[:provider]&.to_sym)
        redirect_to Rails.application.routes.url_helpers.public_send("user_#{params[:provider]}_omniauth_authorize_path")
      else
        redirect_to new_user_session_url
      end

      nil
    end
  end

  resource_owner_from_credentials do |_routes|
    oauth_application = Doorkeeper::Application.find_by!(uid: params[:client_id])
    next unless oauth_application.allow_password_grant?

    user = User.find_by!(email: params[:username])
    next unless user&.valid_for_authentication? { user.valid_password?(params[:password]) } &&
                user.active_for_authentication?

    request.env['warden'].set_user(user, scope: :user, store: false)
    user
  end

  # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
  admin_authenticator do
    current_user || redirect_to(new_user_session_url)
  end

  # Authorization Code expiration time (default 10 minutes).
  # authorization_code_expires_in 10.minutes

  # Assign a custom TTL for tokens.
  # see Doorkeeper::OAuth::GRANT_TYPES for other types
  custom_access_token_expires_in do |oauth_client|
    #   oauth_client.application.additional_settings.implicit_oauth_expiration
    if oauth_client.scopes.include?('legacy_session')
      3.months # TODO: shorten once we can transparently refresh access tokens
    elsif oauth_client.grant_type == Doorkeeper::OAuth::CLIENT_CREDENTIALS
      30.minutes.to_i
    else
      8.hours.to_i
    end
  end

  # Use a custom class for generating the access token.
  # https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
  # access_token_generator '::Doorkeeper::JWT'

  # The controller Doorkeeper::ApplicationController inherits from.
  # Defaults to ActionController::Base.
  # https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
  # base_controller 'ApplicationController'

  # Reuse access token for the same resource owner within an application (disabled by default)
  # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
  # reuse_access_token

  # Issue access tokens with refresh token (disabled by default)
  use_refresh_token

  # Provide support for an owner to be assigned to each registered application (disabled by default)
  # Optional parameter confirmation: true (default false) if you want to enforce ownership of
  # a registered application
  # Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
  enable_application_owner confirmation: false

  # Define access token scopes for your provider
  # For more information go to
  # https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes
  # default_scopes  :public
  # optional_scopes :write, :update

  # Change the way client credentials are retrieved from the request object.
  # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  # falls back to the `:client_id` and `:client_secret` params from the `params` object.
  # Check out the wiki for more information on customization
  # client_credentials :from_basic, :from_params

  # Change the way access token is authenticated from the request object.
  # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  # falls back to the `:access_token` or `:bearer_token` params from the `params` object.
  # Check out the wiki for more information on customization
  # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param

  # Change the native redirect uri for client apps
  # When clients register with the following redirect uri, they won't be redirected to any server and the authorization code will be displayed within the provider
  # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
  # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
  #
  # native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'

  # Forces the usage of the HTTPS protocol in non-native redirect uris (enabled
  # by default in non-development environments). OAuth2 delegates security in
  # communication to the HTTPS protocol so it is wise to keep this enabled.
  #
  # force_ssl_in_redirect_uri !Rails.env.development?

  # Specify what grant flows are enabled in array of Strings. The valid
  # strings and the flows they enable are:
  #
  # "authorization_code" => Authorization Code Grant Flow
  # "implicit"           => Implicit Grant Flow
  # "password"           => Resource Owner Password Credentials Grant Flow
  # "client_credentials" => Client Credentials Grant Flow
  #
  # If not specified, Doorkeeper enables authorization_code and
  # client_credentials.
  #
  # implicit and password grant flows have risks that you should understand
  # before enabling:
  #   http://tools.ietf.org/html/rfc6819#section-4.4.2
  #   http://tools.ietf.org/html/rfc6819#section-4.4.3
  #
  grant_flows %w[authorization_code client_credentials password]

  # Under some circumstances you might want to have applications auto-approved,
  # so that the user skips the authorization step.
  # For example if dealing with a trusted application.
  skip_authorization do |_resource_owner, client|
    client.application.skip_authorization?
  end

  # WWW-Authenticate Realm (default "Doorkeeper").
  # realm "Doorkeeper"
end

Ruby version: ruby 2.7.4p191

Gemfile.lock:

Gemfile.lock content ``` GIT remote: git@github.com:SenteraLLC/product-catalog.git revision: fb5010c1fc8d3f5897874a5628f617e2728f670b tag: v1.0.5 specs: sentera-product-catalog (1.0.5) GIT remote: https://github.com/EdCordata/resque-web.git revision: a66c167aa917f4785ea9c3ecfef6832f741626d3 branch: feat/fix-resque-web-views specs: resque-web (0.0.12) coffee-rails font-awesome-sass jquery-rails resque sass-rails twitter-bootstrap-rails GIT remote: https://github.com/stadia/activerecord-mysql2rgeo-adapter.git revision: 6317425f7686d42acb893ef0e281490ec99bfa81 branch: master specs: activerecord-mysql2rgeo-adapter (7.0.0) activerecord (~> 7.0.0) rgeo-activerecord (~> 7.0.0) PATH remote: vendor/gems/remote_lock specs: remote_lock (1.2.0) GEM remote: https://rubygems.org/ specs: abstract_method (1.2.1) actioncable (7.0.4.3) actionpack (= 7.0.4.3) activesupport (= 7.0.4.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) actionmailbox (7.0.4.3) actionpack (= 7.0.4.3) activejob (= 7.0.4.3) activerecord (= 7.0.4.3) activestorage (= 7.0.4.3) activesupport (= 7.0.4.3) mail (>= 2.7.1) net-imap net-pop net-smtp actionmailer (7.0.4.3) actionpack (= 7.0.4.3) actionview (= 7.0.4.3) activejob (= 7.0.4.3) activesupport (= 7.0.4.3) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) actionpack (7.0.4.3) actionview (= 7.0.4.3) activesupport (= 7.0.4.3) rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) actiontext (7.0.4.3) actionpack (= 7.0.4.3) activerecord (= 7.0.4.3) activestorage (= 7.0.4.3) activesupport (= 7.0.4.3) globalid (>= 0.6.0) nokogiri (>= 1.8.5) actionview (7.0.4.3) activesupport (= 7.0.4.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) active_admin_datetimepicker (1.0.0) activeadmin (>= 2.0, < 3.a) activeadmin (2.13.1) arbre (~> 1.2, >= 1.2.1) formtastic (>= 3.1, < 5.0) formtastic_i18n (~> 0.4) inherited_resources (~> 1.7) jquery-rails (~> 4.2) kaminari (~> 1.0, >= 1.2.1) railties (>= 6.1, < 7.1) ransack (>= 2.1.1, < 4) activeadmin-searchable_select (1.6.0) activeadmin (>= 1.x, < 3) jquery-rails (>= 3.0, < 5) select2-rails (~> 4.0) activejob (7.0.4.3) activesupport (= 7.0.4.3) globalid (>= 0.3.6) activemodel (7.0.4.3) activesupport (= 7.0.4.3) activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) activerecord (7.0.4.3) activemodel (= 7.0.4.3) activesupport (= 7.0.4.3) activerecord-import (1.4.1) activerecord (>= 4.2) activerecord_json_validator (2.1.3) activerecord (>= 4.2.0, < 8) json_schemer (~> 0.2.18) activeresource (6.0.0) activemodel (>= 6.0) activemodel-serializers-xml (~> 1.0) activesupport (>= 6.0) activestorage (7.0.4.3) actionpack (= 7.0.4.3) activejob (= 7.0.4.3) activerecord (= 7.0.4.3) activesupport (= 7.0.4.3) marcel (~> 1.0) mini_mime (>= 1.1.0) activesupport (7.0.4.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) addressable (2.8.2) public_suffix (>= 2.0.2, < 6.0) aggregate_root (2.9.1) ruby_event_store (= 2.9.1) airbrake (13.0.3) airbrake-ruby (~> 6.0) airbrake-ruby (6.2.1) rbtree3 (~> 0.6) ancestry (4.2.0) activerecord (>= 5.2.6) ansi (1.5.0) apipie-rails (0.9.3) actionpack (>= 5.0) activesupport (>= 5.0) arbre (1.5.0) activesupport (>= 3.0.0, < 7.1) ruby2_keywords (>= 0.0.2, < 1.0) arkency-command_bus (0.4.1) concurrent-ruby ast (2.4.2) atlassian-jwt (0.2.1) jwt (~> 2.1) attr_extras (7.1.0) autoprefixer-rails (10.4.13.0) execjs (~> 2) aws-eventstream (1.2.0) aws-partitions (1.739.0) aws-sdk-batch (1.69.0) aws-sdk-core (~> 3, >= 3.165.0) aws-sigv4 (~> 1.1) aws-sdk-cloudwatchlogs (1.62.0) aws-sdk-core (~> 3, >= 3.165.0) aws-sigv4 (~> 1.1) aws-sdk-core (3.171.0) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.5) jmespath (~> 1, >= 1.6.1) aws-sdk-kms (1.63.0) aws-sdk-core (~> 3, >= 3.165.0) aws-sigv4 (~> 1.1) aws-sdk-lambda (1.92.0) aws-sdk-core (~> 3, >= 3.165.0) aws-sigv4 (~> 1.1) aws-sdk-s3 (1.120.0) aws-sdk-core (~> 3, >= 3.165.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.4) aws-sdk-sagemaker (1.171.0) aws-sdk-core (~> 3, >= 3.165.0) aws-sigv4 (~> 1.1) aws-sdk-sqs (1.53.0) aws-sdk-core (~> 3, >= 3.165.0) aws-sigv4 (~> 1.1) aws-sdk-states (1.52.0) aws-sdk-core (~> 3, >= 3.165.0) aws-sigv4 (~> 1.1) aws-sigv4 (1.5.2) aws-eventstream (~> 1, >= 1.0.2) batch-loader (2.0.1) bcrypt (3.1.18) bindex (0.8.1) bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) sassc (>= 2.0.0) bson (4.15.0) builder (3.2.4) byebug (11.1.3) carmen (1.1.3) activesupport (>= 3.0.0) chargify_api_ares (1.4.15) activeresource (>= 3.2.16) choice (0.2.0) city-state (0.1.0) rubyzip (>= 1.1) coderay (1.1.3) coffee-rails (5.0.0) coffee-script (>= 2.2.0) railties (>= 5.2.0) coffee-script (2.4.1) coffee-script-source execjs coffee-script-source (1.12.2) commonjs (0.2.7) concurrent-ruby (1.2.2) connection_pool (2.4.0) content_disposition (1.0.0) country_state_select (3.2.0) city-state rails crack (0.4.5) rexml crass (1.0.6) database_cleaner (2.0.2) database_cleaner-active_record (>= 2, < 3) database_cleaner-active_record (2.1.0) activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) date (3.3.3) dbf (4.2.2) devise (4.9.2) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) responders warden (~> 1.2.3) diff-lcs (1.5.0) docile (1.4.0) doorkeeper (5.6.3) railties (>= 5) doorkeeper-openid_connect (1.8.5) doorkeeper (>= 5.5, < 5.7) jwt (>= 2.5) dotiw (5.3.3) activesupport i18n eav_hashes (1.1.0) rails (>= 3.2.7) ecma-re-validator (0.4.0) regexp_parser (~> 2.2) enumerize (2.6.1) activesupport (>= 3.2) erubi (1.12.0) erubis (2.7.0) et-orbi (1.2.7) tzinfo eventmachine (1.2.7) execjs (2.8.1) exifr (1.3.10) ey_config (0.0.7) factory_bot (6.2.1) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) factory_bot (~> 6.2.0) railties (>= 5.0.0) fakeredis (0.8.0) redis (~> 4.1) faraday (0.17.6) multipart-post (>= 1.2, < 3) faraday_middleware (0.10.1) faraday (>= 0.7.4, < 1.0) faye-websocket (0.10.9) eventmachine (>= 0.12.0) websocket-driver (>= 0.5.1) ffaker (2.21.0) ffi (1.15.5) font-awesome-rails (4.7.0.8) railties (>= 3.2, < 8.0) font-awesome-sass (6.4.0) sassc (~> 2.0) formtastic (4.0.0) actionpack (>= 5.2.0) formtastic_i18n (0.7.0) fugit (1.8.1) et-orbi (~> 1, >= 1.2.7) raabro (~> 1.4) gdal (3.0.0) gem-licenses (0.2.2) geokit (1.14.0) geokit-rails (2.5.0) geokit (~> 1.5) rails (>= 3.0) globalid (1.1.0) activesupport (>= 5.0) graphiql-rails (1.9.0) railties sprockets-rails graphql (2.0.20) graphql-metrics (5.0.4) concurrent-ruby (>= 1.1.0) graphql (>= 1.12.10) haml (6.1.1) temple (>= 0.8.2) thor tilt haml-rails (2.1.0) actionpack (>= 5.1) activesupport (>= 5.1) haml (>= 4.0.6) railties (>= 5.1) hana (1.3.7) has_scope (0.8.1) actionpack (>= 5.2) activesupport (>= 5.2) hashdiff (1.0.1) hashie (5.0.0) health_check (3.1.0) railties (>= 5.0) html2haml (2.3.0) erubis (~> 2.7.0) haml (>= 4.0) nokogiri (>= 1.6.0) ruby_parser (~> 3.5) httparty (0.21.0) mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) i18n (1.12.0) concurrent-ruby (~> 1.0) indefinite_article (0.2.5) activesupport inherited_resources (1.13.1) actionpack (>= 5.2, < 7.1) has_scope (~> 0.6) railties (>= 5.2, < 7.1) responders (>= 2, < 4) jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) jira-ruby (2.3.0) activesupport atlassian-jwt multipart-post oauth (~> 0.5, >= 0.5.0) jmespath (1.6.2) jquery-rails (4.5.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (2.6.3) json-schema (3.0.0) addressable (>= 2.8) json_expressions (0.9.0) json_schemer (0.2.24) ecma-re-validator (~> 0.3) hana (~> 1.3) regexp_parser (~> 2.0) uri_template (~> 0.7) jwt (2.7.0) kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) kaminari-activerecord (= 1.2.2) kaminari-core (= 1.2.2) kaminari-actionview (1.2.2) actionview kaminari-core (= 1.2.2) kaminari-activerecord (1.2.2) activerecord kaminari-core (= 1.2.2) kaminari-core (1.2.2) launchy (2.5.2) addressable (~> 2.8) less (2.6.0) commonjs (~> 0.2.7) less-rails (4.0.0) actionpack (>= 4) less (~> 2.6.0) sprockets (>= 2) letter_opener (1.8.1) launchy (>= 2.2, < 3) loofah (2.20.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.8.1) mini_mime (>= 0.1.1) net-imap net-pop net-smtp marcel (1.0.2) memory_profiler (1.0.1) method_source (1.0.0) mini_mime (1.1.2) mini_portile2 (2.8.1) minitest (5.18.0) mixpanel-ruby (2.3.0) mongo (2.18.2) bson (>= 4.14.1, < 5.0.0) mongoid (8.0.3) activemodel (>= 5.1, < 7.1, != 7.0.0) mongo (>= 2.18.0, < 3.0.0) ruby2_keywords (~> 0.0.5) mono_logger (1.1.1) multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.3.0) mustermann (3.0.0) ruby2_keywords (~> 0.0.1) mysql2 (0.5.5) nested_form (0.3.2) net-imap (0.3.4) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.1) timeout net-smtp (0.3.3) net-protocol newrelic_rpm (9.1.0) nio4r (2.5.9) nokogiri (1.14.2) mini_portile2 (~> 2.8.0) racc (~> 1.4) oauth (0.5.0) oauth2 (1.4.11) faraday (>= 0.17.3, < 3.0) jwt (>= 1.0, < 3.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 4) omniauth (1.9.2) hashie (>= 3.4.6) rack (>= 1.6.2, < 3) omniauth-saml (1.10.3) omniauth (~> 1.3, >= 1.3.2) ruby-saml (~> 1.9) optimist (3.0.1) orm_adapter (0.5.0) paper_trail (14.0.0) activerecord (>= 6.0) request_store (~> 1.4) parallel (1.22.1) parallel_tests (4.2.0) parallel paranoia (2.6.1) activerecord (>= 5.1, < 7.1) parser (3.2.2.0) ast (~> 2.4.1) patience_diff (1.2.0) optimist (~> 3.0) pdf-core (0.9.0) pkg-config (1.5.1) possessive (1.0.1) prawn (2.4.0) pdf-core (~> 0.9.0) ttfunk (~> 1.7) prawn-table (0.2.2) prawn (>= 1.3.0, < 3.0.0) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) pry-byebug (3.10.1) byebug (~> 11.0) pry (>= 0.13, < 0.15) psych (5.1.0) stringio public_suffix (5.0.1) puma (6.2.1) nio4r (~> 2.0) pundit (2.3.0) activesupport (>= 3.0.0) raabro (1.4.0) racc (1.6.2) rack (2.2.6.4) rack-cors (2.0.1) rack (>= 2.0.0) rack-mini-profiler (3.0.0) rack (>= 1.2.0) rack-protection (3.0.5) rack rack-proxy (0.7.6) rack rack-rewrite (1.5.1) rack-test (2.1.0) rack (>= 1.3) rails (7.0.4.3) actioncable (= 7.0.4.3) actionmailbox (= 7.0.4.3) actionmailer (= 7.0.4.3) actionpack (= 7.0.4.3) actiontext (= 7.0.4.3) actionview (= 7.0.4.3) activejob (= 7.0.4.3) activemodel (= 7.0.4.3) activerecord (= 7.0.4.3) activestorage (= 7.0.4.3) activesupport (= 7.0.4.3) bundler (>= 1.15.0) railties (= 7.0.4.3) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) activesupport (>= 5.0.1.rc1) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-erd (1.7.2) activerecord (>= 4.2) activesupport (>= 4.2) choice (~> 0.2.0) ruby-graphviz (~> 1.2) rails-html-sanitizer (1.5.0) loofah (~> 2.19, >= 2.19.1) rails_event_store (2.9.1) activejob (>= 6.0) activemodel (>= 6.0) activesupport (>= 6.0) aggregate_root (= 2.9.1) arkency-command_bus (>= 0.4) rails_event_store_active_record (= 2.9.1) ruby_event_store (= 2.9.1) ruby_event_store-browser (= 2.9.1) rails_event_store_active_record (2.9.1) ruby_event_store-active_record (= 2.9.1) railties (7.0.4.3) actionpack (= 7.0.4.3) activesupport (= 7.0.4.3) method_source rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) ransack (3.2.1) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n ratelimit (1.0.4) redis (>= 3.0.0) redis-namespace (>= 1.0.0) rbtree3 (0.7.0) redis (4.8.1) redis-client (0.14.1) connection_pool redis-namespace (1.10.0) redis (>= 4) redlock (1.3.2) redis (>= 3.0.0, < 6.0) regexp_parser (2.7.0) request_store (1.5.1) rack (>= 1.4) responders (3.1.0) actionpack (>= 5.2) railties (>= 5.2) resque (2.1.0) mono_logger (~> 1.0) multi_json (~> 1.0) redis-namespace (~> 1.6) sinatra (>= 0.9.2) vegas (~> 0.1.2) resque-retry (1.7.6) resque (>= 1.25, < 3.0) resque-scheduler (~> 4.0) resque-scheduler (4.8.0) mono_logger (~> 1.0) redis (>= 3.3) resque (>= 1.27) rufus-scheduler (~> 3.2, != 3.3) resque-scheduler-web (1.1.0) resque-scheduler (~> 4.0) resque-web (~> 0.0.8) rexml (3.2.5) rgeo (2.4.0) rgeo-activerecord (7.0.1) activerecord (>= 5.0) rgeo (>= 1.0.0) rgeo-geojson (2.1.1) rgeo (>= 1.0.0) rgeo-proj4 (2.0.1) rgeo (~> 2.0) rgeo-shapefile (3.0.0) dbf (~> 4.0) rgeo (>= 1.0) rmagick (5.2.0) pkg-config (~> 1.4) roda (3.66.0) rack rolify (6.0.1) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) rspec-mocks (~> 3.12.0) rspec-activemodel-mocks (1.1.0) activemodel (>= 3.0) activesupport (>= 3.0) rspec-mocks (>= 2.99, < 4.0) rspec-core (3.12.1) rspec-support (~> 3.12.0) rspec-expectations (3.12.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-mocks (3.12.5) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-rails (6.0.1) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) rspec-core (~> 3.11) rspec-expectations (~> 3.11) rspec-mocks (~> 3.11) rspec-support (~> 3.11) rspec-sidekiq (3.1.0) rspec-core (~> 3.0, >= 3.0.0) sidekiq (>= 2.4.0) rspec-support (3.12.0) rubocop (1.49.0) json (~> 2.3) parallel (~> 1.10) parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) rubocop-ast (>= 1.28.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.28.0) parser (>= 3.2.1.0) rubocop-capybara (2.17.1) rubocop (~> 1.41) rubocop-graphql (1.1.1) rubocop (>= 0.87, < 2) rubocop-rails (2.18.0) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) rubocop-rspec (2.19.0) rubocop (~> 1.33) rubocop-capybara (~> 2.17) ruby-graphviz (1.2.5) rexml ruby-prof (1.6.1) ruby-progressbar (1.13.0) ruby-saml (1.15.0) nokogiri (>= 1.13.10) rexml ruby2_keywords (0.0.5) ruby_event_store (2.9.1) concurrent-ruby (~> 1.0, >= 1.1.6) ruby_event_store-active_record (2.9.1) activerecord (>= 6.0) ruby_event_store (= 2.9.1) ruby_event_store-browser (2.9.1) rack ruby_event_store (= 2.9.1) ruby_event_store-rspec (2.9.1) rspec (~> 3.0) ruby_event_store-sidekiq_scheduler (0.1.1) ruby_event_store (>= 2.0.0, < 3.0.0) ruby_parser (3.20.0) sexp_processor (~> 4.16) rubyzip (1.3.0) rufus-scheduler (3.8.2) fugit (~> 1.1, >= 1.1.6) safety_mailer (0.0.10) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) sassc (2.4.0) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) sassc (>= 2.0) sprockets (> 3.0) sprockets-rails tilt scenic (1.7.0) activerecord (>= 4.0.0) railties (>= 4.0.0) scenic-mysql_adapter (1.0.1) mysql2 scenic (>= 1.4.0) seed-fu (2.3.9) activerecord (>= 3.1) activesupport (>= 3.1) select2-rails (4.0.13) semantic_range (3.0.0) sendgrid (1.2.4) json sexp_processor (4.16.1) shakapacker (6.6.0) activesupport (>= 5.2) rack-proxy (>= 0.6.1) railties (>= 5.2) semantic_range (>= 2.3.0) shoulda-callback-matchers (1.1.4) activesupport (>= 3) shoulda-matchers (5.3.0) activesupport (>= 5.2.0) sidekiq (7.0.7) concurrent-ruby (< 2) connection_pool (>= 2.3.0) rack (>= 2.2.4) redis-client (>= 0.11.0) simple_form (5.2.0) actionpack (>= 5.2) activemodel (>= 5.2) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-console (0.9.1) ansi simplecov terminal-table simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) sinatra (3.0.5) mustermann (~> 3.0) rack (~> 2.2, >= 2.2.4) rack-protection (= 3.0.5) tilt (~> 2.0) slack-api (1.6.1) faraday (~> 0.11) faraday_middleware (~> 0.10.0) faye-websocket (~> 0.10.6) multi_json (~> 1.0, >= 1.0.3) sprockets (4.2.0) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) stackprof (0.2.24) state_machines (0.5.0) state_machines-activemodel (0.8.0) activemodel (>= 5.1) state_machines (>= 0.5.0) state_machines-activerecord (0.8.0) activerecord (>= 5.1) state_machines-activemodel (>= 0.8.0) stringio (3.0.5) super_diff (0.9.0) attr_extras (>= 6.2.4) diff-lcs patience_diff temple (0.10.0) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) thor (1.2.1) tilt (2.1.0) timecop (0.9.6) timeliness (0.4.5) timeout (0.3.2) ttfunk (1.7.0) twitter-bootstrap-rails (5.0.0) actionpack (>= 5.0, < 8.0) execjs (~> 2.7) less-rails (>= 3.0, < 5.0) railties (>= 5.0, < 8.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) ultrahook (1.0.1) json (>= 1.8.0) unicode-display_width (2.4.2) uppy-s3_multipart (1.2.1) aws-sdk-s3 (~> 1.0) content_disposition (~> 1.0) roda (>= 2.27, < 4) uri_template (0.7.0) validates_timeliness (7.0.0.beta2) activemodel (>= 7.0.0, < 8) timeliness (>= 0.3.10, < 1) vegas (0.1.11) rack (>= 1.0.0) warden (1.2.9) rack (>= 2.0.9) web-console (4.2.0) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) webmock (3.18.1) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) with_model (2.1.6) activerecord (>= 5.2) zeitwerk (2.6.7) PLATFORMS ruby x86_86-linux DEPENDENCIES abstract_method active_admin_datetimepicker activeadmin activeadmin-searchable_select activerecord-import activerecord-mysql2rgeo-adapter! activerecord_json_validator activeresource addressable airbrake ancestry (= 4.2.0) apipie-rails aws-sdk-batch aws-sdk-cloudwatchlogs aws-sdk-lambda aws-sdk-s3 aws-sdk-sagemaker aws-sdk-sqs aws-sdk-states batch-loader bootstrap-sass bundler (= 1.17.3) carmen chargify_api_ares country_state_select database_cleaner devise doorkeeper (= 5.6.3) doorkeeper-openid_connect dotiw eav_hashes enumerize exifr ey_config factory_bot_rails fakeredis ffaker font-awesome-rails font-awesome-sass gdal gem-licenses geokit-rails graphiql-rails graphql graphql-metrics haml haml-rails health_check html2haml httparty indefinite_article jbuilder jira-ruby json-schema json_expressions kaminari letter_opener memory_profiler mixpanel-ruby mongoid mysql2 nested_form newrelic_rpm oauth (= 0.5.0) oauth2 (< 2) omniauth-saml (< 2) paper_trail parallel parallel_tests paranoia possessive prawn prawn-table pry pry-byebug psych puma pundit rack-cors rack-mini-profiler rack-rewrite rails (= 7.0.4.3) rails-controller-testing rails-erd rails_event_store ratelimit redis (~> 4.6) redlock (= 1.3.2) remote_lock! resque (= 2.1.0) resque-retry resque-scheduler resque-scheduler-web resque-web! rgeo rgeo-geojson rgeo-proj4 (< 3) rgeo-shapefile rmagick rolify rspec-activemodel-mocks rspec-mocks rspec-rails rspec-sidekiq rubocop rubocop-graphql rubocop-rails rubocop-rspec ruby-prof ruby_event_store-rspec ruby_event_store-sidekiq_scheduler rubyzip (~> 1.2) safety_mailer sass-rails scenic scenic-mysql_adapter seed-fu sendgrid sentera-product-catalog! shakapacker shoulda-callback-matchers shoulda-matchers sidekiq simple_form simplecov simplecov-console slack-api stackprof state_machines state_machines-activerecord super_diff timecop uglifier ultrahook uppy-s3_multipart validates_timeliness (~> 7.0.0.beta1) web-console webmock with_model BUNDLED WITH 1.17.3 ```
nbulaj commented 1 year ago

Hey @denisahearn

Do you still have an issue when upgrading to Doorkeeper 5.6.6 ?

denisahearn commented 1 year ago

@nbulaj Yes, the same issue happens with doorkeeper 5.6.6. In fact that's the version we tried upgrading to yesterday when we experienced the issue. I isolated 5.6.3 as the version that introduced the issue.

nbulaj commented 1 year ago

Could be related to changes in config evaluation, but it's always so hard to debug such things unfortunately https://github.com/doorkeeper-gem/doorkeeper/pull/1627/files

AmShaegar13 commented 4 months ago

Hey @nbulaj

I ran into a similar problem with assets:precompile and doorkeeper. I run precompile in a CI context where there is no database configuration available so it fails when it tries to access certain environment variables in config/database.yml which shouldn't be loaded at all. This is called by the same lines in doorkeeper like for @denisahearn.

To me it looks like orm hooks are run too early and we need to lazy load here as well because access_token_class.constantize in lib/doorkeeper/config.rb:434 loads ActiveRecord::Base too early. I tried to do so by wrapping it like so lib/doorkeeper/engine.rb:23:

    config.to_prepare do
      ActiveSupport.on_load(:active_record) do
        Doorkeeper.run_orm_hooks
      end
    end

At least this fixed the problem for me while keeping everything else functional. However, I am not an expert regarding Rails internals or doorkeeper. I am using doorkeeper for the first time here.

Maybe this helps you isolate or even fixes the problem. :)