Skip to content
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

NameError ActiveRecord::AttributeSet after redeploying #1210

Closed
stephanebruckert opened this issue Sep 7, 2018 · 3 comments
Closed

NameError ActiveRecord::AttributeSet after redeploying #1210

stephanebruckert opened this issue Sep 7, 2018 · 3 comments

Comments

@stephanebruckert
Copy link

stephanebruckert commented Sep 7, 2018

I just deployed my app (capistrano, passenger, nginx) after a month, and I am getting a NameError ActiveRecord::AttributeSet at line 48 in the sessions controller (overridden in my own controller)

sign_in(:users, @resource, store: false, bypass: false)

I can't see any deeper than that so it's hard for me to find what's wrong. I saw that it is a Devise method.

  • Version: v0.2.0, ruby 2.4, rails 5.2.1
  • Rails Stacktrace:
I, [2018-09-07T16:47:25.375364 #102279]  INFO -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41] Started POST "/api/auth/sign_in" for 127.0.0.1 at 2018-09-07 16:47:25 +0100
I, [2018-09-07T16:47:25.375606 #102279]  INFO -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41] Chewy request strategy is `atomic`
I, [2018-09-07T16:47:25.387592 #102279]  INFO -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41] Processing by Api::V4::DeviseTokenAuth::SessionsController#create as application/vnd.api+json application/vnd.hivebench-v4+json
I, [2018-09-07T16:47:25.387682 #102279]  INFO -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41]   Parameters: {"password"=>"[FILTERED]", "login"=>"stephanebruckert"}
D, [2018-09-07T16:47:25.422876 #102279] DEBUG -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41]   User Load (2.2ms)  SELECT  "users".* FROM "users" WHERE (LOWER(email) = 'stephanebruckert' OR LOWER(username) = 'stephanebruckert') ORDER BY "users"."id" ASC LIMIT $1  [["LIMIT", 1]]
D, [2018-09-07T16:47:25.787855 #102279] DEBUG -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41]    (16.9ms)  BEGIN
D, [2018-09-07T16:47:26.165986 #102279] DEBUG -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41]   User Exists (32.2ms)  SELECT  1 AS one FROM "users" WHERE LOWER("users"."username") = LOWER($1) AND "users"."id" != $2 LIMIT $3  [["username", "stephanebruckert"], ["id", 43], ["LIMIT", 1]]
D, [2018-09-07T16:47:26.252015 #102279] DEBUG -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41]   User Update (32.1ms)  UPDATE "users" SET "tokens" = $1, "updated_at" = $2 WHERE "users"."id" = $3  [["tokens", "{\"UGKCe9WQ_8gizGBKmXuFIA\":{\"token\":\"$2a$10$d.lw65nHuOtQLmwBybr8eu2niPAznO4J4eoEB.qAev3bTga/I/AHq\",\"expiry\":1538911685},\"N26RlQYam1tGpzkGOIQzyw\":{\"token\":\"$2a$10$6Id3aKPZBgIkw5YMWTYpoOTxhIaek5tOa7eJUIC3/rGSY54SU/3SW\",\"expiry\":1538911699},\"MGJ-_B-sjamMC8k_BphZNw\":{\"token\":\"$2a$10$7dK8nYKFGsba1M2XSv/DQOa93S12EbXWY7betKz432OgBwJRmFm6G\",\"expiry\":1538913829},\"7usY5BZVBnX7AyJ-xO25aA\":{\"token\":\"$2a$10$DPCRRkvmD1r5LcrQ/uFL3O1IpiDhrC3lXlRI07jHryGJHKFYbqUZW\",\"expiry\":1538913849},\"D3zfp3WCDNZ8tEy0UAd4yg\":{\"token\":\"$2a$10$9sawJCGCXCZvnTWRVumQqOeYG5qqdZnN8rrdBatbqhxebLxvqLI9e\",\"expiry\":1538914190,\"last_token\":\"$2a$10$F5HlYshka2s3RUorljPXtOZqWGzrHW.ys67HAmC8dzWI1WQqL0S.m\",\"updated_at\":\"2018-09-07T13:09:50.554+01:00\"},\"dHqNgwjnIOAOwTI4CYeI0A\":{\"token\":\"$2a$10$W0AoYhyS8BT9iLXryYHy7uKjGX03jNrcu7PRFJ7TDma0.QvL3UGmi\",\"expiry\":1538915102},\"1z81MKO6JnY8YVI4NERbXw\":{\"token\":\"$2a$10$XFfujF8J2KNXgd.zX3vFYet4RwX6pLLBObRODMxH9bfQ/HysxOeMK\",\"expiry\":1538915178,\"last_token\":\"$2a$10$4oMIBpm8QXCOBrsTLcabvOe8YHCVNlL8tZPpZ3xz4X9D5NhPBaiCW\",\"updated_at\":\"2018-09-07T13:26:22.821+01:00\"},\"JlDUxrKBli77QWj7fp7XLA\":{\"token\":\"$2a$10$wWL7Az5hTbdp99pcE.UkDOM1JQNp5LkvOtdAewywdGbj6lGULC0xG\",\"expiry\":1538915515},\"doXxrmx9e_WmQxj1KUWCLw\":{\"token\":\"$2a$10$6HzYPmHYgDRYgEs2PG4ycuZgYPKRrRCGQMCpuh0cj5vPwERk4OXRO\",\"expiry\":1538915560},\"cONT-HqIvYUg8gOdxHPPmA\":{\"token\":\"$2a$10$26o5TReiWQVjlZLxkosRmOjuViYuiA2HwJVyQ7DEUdY9JGRaRLWOu\",\"expiry\":1538916272,\"last_token\":\"$2a$10$P4Qng6p1DjOkHc7VpLR/XOXG8J9.Jq0vVV162JeiGjZBX3etB.nx2\",\"updated_at\":\"2018-09-07T13:44:57.312+01:00\"},\"KI09yMe7o2mEHAGV67KjLQ\":{\"token\":\"$2a$10$D98RW5QIAXM8cAPQj8fuW.oH3z3YPl7Qgj7cPvWLacLoyFODE1P8G\",\"expiry\":1538917903},\"AsLNATjxyslQFnuar4TGbg\":{\"token\":\"$2a$10$g6Esj0I2idzByP.k4qyTpeRrvl48i4EUuXwTorObUO5FMBc7T5f1u\",\"expiry\":1538920172},\"EaeafbFOrFBOmhLIbrcQqA\":{\"token\":\"$2a$10$anfAakTM8Q2rOXLh7SI1i.uxOlBOBWe0DPbHMpVYUkbEZTrfnnOdO\",\"expiry\":1538920609},\"4K8YiRA3wGcpjqBwyvxHyQ\":{\"token\":\"$2a$10$1.y/siAZ86UoMk07IcWDwu1i9OA8T96FjlmjdvUJEEPcKjdcny8eC\",\"expiry\":1538921098},\"i4I9s_DxJa85L82T6IF91w\":{\"token\":\"$2a$10$n0nod0NabfsM8sYsySHVYeKMVbdZotw2aSMCeP/BVdxSfwufD1JW2\",\"expiry\":1538921429},\"lJtfohmmlRfHkodCNcPEPg\":{\"token\":\"$2a$10$1vPKp.OX6IcJ7lhmmxFgp.dGb0hm7O3cqBltlpgVlCippZ5cOAtUq\",\"expiry\":1538921430},\"31UwytcGXkXHLTSSJeOmFA\":{\"token\":\"$2a$10$n1ttVAJcrQ.3Lq52rLqVSuCjVoisPiMSq7laFaecYoWKrWDzE9fbK\",\"expiry\":1538921500},\"8nzrJD5ZSxO0PbDtiXd2TA\":{\"token\":\"$2a$10$gliEVjFv1/.12zJXtKRNAekFpxFpfoEtQAP1/1hPhgJS7UpWMDdiu\",\"expiry\":1538922492},\"uqAOZIJKGH27lYIBxc8HQQ\":{\"token\":\"$2a$10$7ZjsTkRdOksgktKBERiuueYD.ScJ.UQGCKxlgLQkpZi2q0zZOouJK\",\"expiry\":1538922791},\"3UE7mUP3k3tic_dO0rI3jw\":{\"token\":\"$2a$10$TfabCvEUOILLbHfiGh7LYulGfaDahwFcVsaz.Dzjdvo6KlNq.wJla\",\"expiry\":1538922830},\"Sa32G0sFridIgGy4FHCucA\":{\"token\":\"$2a$10$PjDJx6NrAYWVuMok1IgeHuudL48ax3GB5.EM8H0dTWWh2lhi0nfL.\",\"expiry\":1538922989},\"fsB4JASw2q_UcYXxvhBGog\":{\"token\":\"$2a$10$6HgdtJlHdr.G5EF8u37up.LQSU6wI2ktXubQfcE/.i6ebB.xkOvmS\",\"expiry\":1538922996},\"HY5sE0zUWt6Yo1nioKPz3A\":{\"token\":\"$2a$10$bW8dlz0edgW33MsGw1TpCeWU6Y5DQzh.MN48.SA2.CKeYMUirq/cC\",\"expiry\":1538923257},\"RfxPPpAUSwXOBxdFiRd1iA\":{\"token\":\"$2a$10$pmR2kJY9qSpGkgy9mI3/huxGvh8Ih2RZzBkP/HcWHgzxuqkVrA3r.\",\"expiry\":1538923967},\"z29NHE3aY6BR5F6xVXQnrw\":{\"token\":\"$2a$10$Dp09SK7xAAnRSnMYhqPCm.aiBg0Booy1UsOcw6B/I/vqFt4y0XM1G\",\"expiry\":1538924139},\"hlKz3T7K1lt3M_T5TgxCbA\":{\"token\":\"$2a$10$YxIXtn7O7urBOwww1kcN3OPD0/pEDtMbF6JJu6uzH11IavN8czjGa\",\"expiry\":1538924143},\"Jtn9M8RDuQaaluMVG1xwkQ\":{\"token\":\"$2a$10$KriLXCUnKanC1ll83r.cq.cKMip/eDS.hDx4tr0PB9H2iBb9uYwqG\",\"expiry\":1538924253},\"8Uu2dgOkRmOQmg6Jv3Xmfg\":{\"token\":\"$2a$10$rMwD0gGqlfBEsqrZN4oZzOxvuQAGhsFtEodl6uHKQFnrw/QGhW4fm\",\"expiry\":1538924258},\"1ZEQaArAKuEI7EtcKZL9pg\":{\"token\":\"$2a$10$ix02JFKRn1a6iOyvpozI3.gLrH6RPcvXmbnq6RyT0dywQRbJtldYW\",\"expiry\":1538924294},\"LCuqiFe6YjL436XS-Rd6qg\":{\"token\":\"$2a$10$7GYrixNI9lndFXemtEPdMOrB61/qjdmOD2r4CsLGNTDpqqvAiPbAW\",\"expiry\":1538925621},\"cKrGZ2Ypn8x-TkXOb9cgzA\":{\"token\":\"$2a$10$1ExBbiVed6NHBw346vaCH..3j/OJlJHHftzWFxK4F7CP5SpWHfbFq\",\"expiry\":1538925772},\"caAPaq5RflgmVP386nPY1Q\":{\"token\":\"$2a$10$gCRJCoqZn6j7VvCHf46D6uzCgxm7dTKAXcNoDdqIBq9AHxPow3Dru\",\"expiry\":1538926565},\"xDM-hJT6I7_ggO_qjmHT-g\":{\"token\":\"$2a$10$mZckWEd8L32OyzvSsKCwieZ/X9oXeY4Rdl13tWx4Weei.JcT1mk.C\",\"expiry\":1538927215},\"n38TRUZuVaASrrgzEIcTAQ\":{\"token\":\"$2a$10$0G/xWoXfFBVlBfk7b32YzOQXKLXTDm1.YkB8/D9DVujWZnOCyJCWe\",\"expiry\":1538927245}}"], ["updated_at", "2018-09-07 15:47:26.203235"], ["id", 43]]
D, [2018-09-07T16:47:26.299508 #102279] DEBUG -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41]    (40.6ms)  COMMIT
I, [2018-09-07T16:47:26.420237 #102279]  INFO -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41] Completed 500 Internal Server Error in 1032ms (ActiveRecord: 280.4ms)
D, [2018-09-07T16:47:26.420603 #102279] DEBUG -- [Bugsnag]: [2177f9ba-807a-4ecd-b864-ebf71f6d9c41] Not notifying due to an invalid api_key
F, [2018-09-07T16:47:26.422472 #102279] FATAL -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41]   
F, [2018-09-07T16:47:26.422678 #102279] FATAL -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41] NameError (uninitialized constant ActiveRecord::AttributeSet
Did you mean?  ActiveRecord::Attributes):
F, [2018-09-07T16:47:26.422786 #102279] FATAL -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41]   
F, [2018-09-07T16:47:26.422912 #102279] FATAL -- : [2177f9ba-807a-4ecd-b864-ebf71f6d9c41] app/controllers/api/v4/devise_token_auth/sessions_controller.rb:48:in `create'
  • Environmental Info:

    • Custom Overrides:
module Api
  module V4
    module DeviseTokenAuth
      class SessionsController < ::DeviseTokenAuth::SessionsController
        def create
          # Check
          field = (resource_params.keys.map(&:to_sym) & resource_class.authentication_keys).first

          @resource = nil
          if field
            q_value = resource_params[field]

            if resource_class.case_insensitive_keys.include?(field)
              q_value.downcase!
            end

            q = "#{field.to_s} = ? AND provider='email'"

            if ActiveRecord::Base.connection.adapter_name.downcase.starts_with? "mysql"
              q = "BINARY " + q
            end

            # Log in by email or username
            if field == :login
              @resource = resource_class.where("LOWER(email) = ? OR LOWER(username) = ?", q_value, q_value).first
            else
              @resource = resource_class.where(q, q_value).first
            end
            # Log in by email or username END
          end

          if @resource && valid_params?(field, q_value) && ([email protected]_to?(:active_for_authentication?) || @resource.active_for_authentication?)
            valid_password = @resource.valid_password?(resource_params[:password])
            if (@resource.respond_to?(:valid_for_authentication?) && [email protected]_for_authentication? { valid_password }) || !valid_password
              render_create_error_bad_credentials
              return
            end
            # create client id
            @client_id = SecureRandom.urlsafe_base64(nil, false)
            @token     = SecureRandom.urlsafe_base64(nil, false)

            @resource.tokens[@client_id] = {
              token: BCrypt::Password.create(@token),
              expiry: (Time.now + ::DeviseTokenAuth.token_lifespan).to_i
            }
            @resource.save
            debugger
            sign_in(:users, @resource, store: false, bypass: false)

            yield @resource if block_given?

            render_create_success
          elsif @resource && !([email protected]_to?(:active_for_authentication?) || @resource.active_for_authentication?)
            render_create_error_not_confirmed
          else
            render_create_error_bad_credentials
          end
        end
      end
    end
  end
end
  • Custom Frontend: ember-simple-auth

Did anyone come across the same issue? Thanks

@MaicolBen
Copy link
Collaborator

please don't use 0.2.0 unless you need #1159, use the latest, can you check again after that?

@stephanebruckert
Copy link
Author

@MaicolBen I rolled back to dta-0.1.43 and it doesn't fix the issue.

@stephanebruckert
Copy link
Author

My issue is now fixed... and I don't understand why.

I deployed an older version of my app and then the latest again, and the issue has disappeared.

It indeed seemed like a configuration (not code) problem as my current codebase is working fine on other servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants