openstax / exchange

OpenStax Exchange
Other
5 stars 5 forks source link

Use of OAuth token results in removed IdentifierAccessPolicy module error #17

Closed kevinburleigh75 closed 9 years ago

kevinburleigh75 commented 9 years ago

I got this error when trying to use an OAuth token. Restarting the server fixed it. @Dantemss noted that this seems to occur after the API docs are regenerated.

Started POST "/oauth/token" for 127.0.0.1 at 2014-12-15 18:16:12 -0600
Processing by Doorkeeper::TokensController#create as application/vnc.exchange.openstax.v1
  Parameters: {"client_id"=>"123", "grant_type"=>"client_credentials", "client_secret"=>"abc"}
  Doorkeeper::Application Load (0.2ms)  SELECT  "oauth_applications".* FROM "oauth_applications" WHERE "oauth_applications"."uid" = ? AND "oauth_applications"."secret" = ?  ORDER BY "oauth_applications"."id" ASC LIMIT 1  [["uid", "123"], ["secret", "abc"]]
   (0.1ms)  begin transaction
  Doorkeeper::AccessToken Exists (0.1ms)  SELECT  1 AS one FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."token" = '67c76ba1d92fe563c091094729da7d62de9aed9ffd8a86999b92e11d47656b2d' LIMIT 1
  SQL (0.3ms)  INSERT INTO "oauth_access_tokens" ("application_id", "created_at", "scopes", "token") VALUES (?, ?, ?, ?)  [["application_id", 1], ["created_at", "2014-12-16 00:16:12.961229"], ["scopes", ""], ["token", "67c76ba1d92fe563c091094729da7d62de9aed9ffd8a86999b92e11d47656b2d"]]
   (2.2ms)  commit transaction
Completed 200 OK in 12ms

Started POST "/api/identifiers" for 127.0.0.1 at 2014-12-15 18:24:15 -0600
Processing by Api::V1::IdentifiersController#create as JSON
  Doorkeeper::AccessToken Load (0.2ms)  SELECT  "oauth_access_tokens".* FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."token" = ?  ORDER BY "oauth_access_tokens"."id" ASC LIMIT 1  [["token", "67c76ba1d92fe563c091094729da7d62de9aed9ffd8a86999b92e11d47656b2d"]]
  Doorkeeper::Application Load (0.1ms)  SELECT  "oauth_applications".* FROM "oauth_applications" WHERE "oauth_applications"."id" = ? LIMIT 1  [["id", 1]]
  Person Load (0.2ms)  SELECT  "people".* FROM "people" WHERE "people"."id" IS NULL  ORDER BY "people"."id" ASC LIMIT 1
An exception occurred: A copy of IdentifierAccessPolicy has been removed from the module tree but is still active!

/Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:466:in `load_missing_constant'
/Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:180:in `const_missing'
/Users/burleigh/dev/openstax/exchange/app/access_policies/identifier_access_policy.rb:7:in `action_allowed?'
/Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/openstax_utilities-4.1.0/lib/openstax/utilities/access_policy.rb:46:in `action_allowed?'
/Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/openstax_utilities-4.1.0/lib/openstax/utilities/access_policy.rb:27:in `require_action_allowed!'
...
/Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/railties-4.2.0.beta2/lib/rails/commands/server.rb:80:in `start'
/Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:80:in `block in server'
/Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `tap'
/Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `server'
/Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
/Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/railties-4.2.0.beta2/lib/rails/commands.rb:17:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
Completed 500 Internal Server Error in 29ms

ArgumentError (A copy of IdentifierAccessPolicy has been removed from the module tree but is still active!):
  app/access_policies/identifier_access_policy.rb:7:in `action_allowed?'
  app/controllers/api/v1/identifiers_controller.rb:36:in `create'

  Rendered /Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_source.erb (8.0ms)
  Rendered /Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_trace.html.erb (3.2ms)
  Rendered /Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_request_and_response.html.erb (1.0ms)
  Rendered /Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_web_console.html.erb (1.0ms)
  Rendered /Users/burleigh/.rvm/gems/ruby-2.1.3@exchange/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/diagnostics.html.erb within rescues/layout (32.1ms)
Dantemss commented 9 years ago

Apipie causes a bunch of stuff to reload. Likely we just have to make the OSU::AccessPolicy stuff resistant to being reloaded.

navilan commented 9 years ago

one option is to sepearate the docs server from the API server. (i.e., don't serve, generate docs on the api server).

Dantemss commented 9 years ago

Well autoloading happens in Dev only (so this bug shouldn't happen in Production) And separate servers in dev is probably not going to happen...

navilan commented 9 years ago

Ah okay. So, during production deploys, how are the API docs updated?

Dantemss commented 9 years ago

From Apipie's documentation it doesn't (or shouldn't) cause controllers to reload in production. So updating the docs (or the controllers for that matter) requires a server restart.

navilan commented 9 years ago

I see. Okay. Thanks @Dantemss

Dantemss commented 9 years ago

Closing in favor of https://github.com/openstax/openstax_utilities/issues/10