heartcombo / devise

Flexible authentication solution for Rails with Warden.
http://blog.plataformatec.com.br/tag/devise/
MIT License
23.89k stars 5.54k forks source link

NoMethodError in Devise::SessionsController#create #5560

Closed ck2000 closed 1 year ago

ck2000 commented 1 year ago

Environment

=> Rails 7.0.4.2 => ruby 3.1.3 (2022-11-24) [x86_64-darwin22] => devise 4.9.0

Current behavior

Log in does not work with the environment described above.

NoMethodError in Devise::SessionsController#create
NoMethodError (undefined method `empty?' for #<User id: 1, platform_id: 1, key: "XXXX", key_code: "XXXX", 
key_id: 1, email: "X@XXXX.com", first_name: "XXX", last_name: "XXXXX", crypted_password: [FILTERED], salt: [FILTERED], state: "active", remember_token_expires_at: nil, password_reset_code: nil, language: "de", activation_code: nil, activated_at: "2009-05-26 00:00:00.000000000 +0000", deleted_at: nil, last_login_at: nil, force_user_to_change_password: nil, created_at: "2009-05-26 00:00:00.000000000 +0000", updated_at: "2023-02-18 08:10:13.000000000 +0000", wrong_logins_count: 0, force_new_password: [FILTERED], ip: nil, note: nil, image_thumb_size: "10.33">):

activemodel (7.0.4.2) lib/active_model/attribute_methods.rb:458:in `method_missing'
rack (2.2.6.2) lib/rack/etag.rb:71:in `block in digest_body'
actionpack (7.0.4.2) lib/action_dispatch/http/response.rb:145:in `each'
actionpack (7.0.4.2) lib/action_dispatch/http/response.rb:145:in `each_chunk'
actionpack (7.0.4.2) lib/action_dispatch/http/response.rb:127:in `each'
actionpack (7.0.4.2) lib/action_dispatch/http/response.rb:75:in `each'
actionpack (7.0.4.2) lib/action_dispatch/http/response.rb:480:in `each'
rack (2.2.6.2) lib/rack/body_proxy.rb:41:in `method_missing'
rack (2.2.6.2) lib/rack/etag.rb:69:in `digest_body'
rack (2.2.6.2) lib/rack/etag.rb:33:in `call'
rack (2.2.6.2) lib/rack/conditional_get.rb:40:in `call'
rack (2.2.6.2) lib/rack/head.rb:12:in `call'
actionpack (7.0.4.2) lib/action_dispatch/http/permissions_policy.rb:38:in `call'
actionpack (7.0.4.2) lib/action_dispatch/http/content_security_policy.rb:36:in `call'
rack (2.2.6.2) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.6.2) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/cookies.rb:704:in `call'
activerecord (7.0.4.2) lib/active_record/migration.rb:603:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (7.0.4.2) lib/active_support/callbacks.rb:99:in `run_callbacks'
actionpack (7.0.4.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/debug_exceptions.rb:28:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/show_exceptions.rb:26:in `call'
railties (7.0.4.2) lib/rails/rack/logger.rb:40:in `call_app'
railties (7.0.4.2) lib/rails/rack/logger.rb:25:in `block in call'
activesupport (7.0.4.2) lib/active_support/tagged_logging.rb:99:in `block in tagged'
activesupport (7.0.4.2) lib/active_support/tagged_logging.rb:37:in `tagged'
activesupport (7.0.4.2) lib/active_support/tagged_logging.rb:99:in `tagged'
railties (7.0.4.2) lib/rails/rack/logger.rb:25:in `call'
sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/remote_ip.rb:93:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/request_id.rb:26:in `call'
rack (2.2.6.2) lib/rack/method_override.rb:24:in `call'
rack (2.2.6.2) lib/rack/runtime.rb:22:in `call'
activesupport (7.0.4.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/server_timing.rb:61:in `block in call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/server_timing.rb:26:in `collect_events'
actionpack (7.0.4.2) lib/action_dispatch/middleware/server_timing.rb:60:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/static.rb:23:in `call'
rack (2.2.6.2) lib/rack/sendfile.rb:110:in `call'
actionpack (7.0.4.2) lib/action_dispatch/middleware/host_authorization.rb:137:in `call'
railties (7.0.4.2) lib/rails/engine.rb:530:in `call'
rack (2.2.6.2) lib/rack/handler/webrick.rb:95:in `service'
webrick (1.8.1) lib/webrick/httpserver.rb:140:in `service'
webrick (1.8.1) lib/webrick/httpserver.rb:96:in `run'
webrick (1.8.1) lib/webrick/server.rb:310:in `block in start_thread'
127.0.0.1 - - [18/Feb/2023:09:10:12 CET] "POST /auth/login HTTP/1.1" 500 74865
http://www.localhost.id2:3000/auth/login -> /auth/login

Code examples: I am using the default devise controllers and views.

Expected behavior

Log in works as expected ....

carlosantoniodasilva commented 1 year ago

@ck2000 this error looks a lot like https://github.com/heartcombo/devise/issues/5558. Have you upgraded your app and had custom code (failure app, parent controller) configured by any chance? Those would have to be removed. See this upgrade example: https://github.com/vincemilo/odin-facebook/pull/1

If not that, have you made any other change to your app, like adding custom respond_to, etc? Are you running with responders 3.1.0? This information will be helpful to troubleshot. Thanks.

ck2000 commented 1 year ago

@ck2000 this error looks a lot like #5558. Have you upgraded your app and had custom code (failure app, parent controller) configured by any chance? Those would have to be removed. See this upgrade example: vincemilo/odin-facebook#1

If not that, have you made any other change to your app, like adding custom respond_to, etc? Are you running with responders 3.1.0? This information will be helpful to troubleshot. Thanks.

Thank you for your quick response. Yes, I have upgraded my app as described in the change log. I am using responders gem v3.1.0. / no changes to respond_to ...

I have some code in my application_controller / nothing special. I am using gem 'exception_notification' If you meant this with failure app.

carlosantoniodasilva commented 1 year ago

@ck2000 and you've removed all custom code like these pieces, right?

https://github.com/vincemilo/odin-facebook/pull/1/files#diff-f3640dd386a7be68e1654ef2770e29c5594e786a7039f2ed79269cc7bf53bdda

https://github.com/vincemilo/odin-facebook/pull/1/files#diff-cb6e8126296dbc007e7625eee863de5c3213ed949b9999ea3418775f65826531

I will try to repro again, but from my previous testing on that other app the only way I could really repro it was keeping those overrides. After removing them, the error went away.

ck2000 commented 1 year ago

Thank you for pointing this out. I have changed the config an go ride of config.parent_controller

Works perfect now. Thank you!

carlosantoniodasilva commented 1 year ago

Awesome, glad to hear it!

gammafly-co commented 1 year ago

@ck2000 and you've removed all custom code like these pieces, right?

https://github.com/vincemilo/odin-facebook/pull/1/files#diff-f3640dd386a7be68e1654ef2770e29c5594e786a7039f2ed79269cc7bf53bdda

https://github.com/vincemilo/odin-facebook/pull/1/files#diff-cb6e8126296dbc007e7625eee863de5c3213ed949b9999ea3418775f65826531

I will try to repro again, but from my previous testing on that other app the only way I could really repro it was keeping those overrides. After removing them, the error went away.

Hey this worked great; thank you @carlosantoniodasilva . Do you know if there is a way to regenerate a clean config/initializers/devise.rb file from the 4.9 package? I would like to make sure I'm running a clean copy. I couldn't find the source file in the repo, so is this automagically generated during Devise install?

ck2000 commented 1 year ago

@ck2000 and you've removed all custom code like these pieces, right?

https://github.com/vincemilo/odin-facebook/pull/1/files#diff-f3640dd386a7be68e1654ef2770e29c5594e786a7039f2ed79269cc7bf53bdda

https://github.com/vincemilo/odin-facebook/pull/1/files#diff-cb6e8126296dbc007e7625eee863de5c3213ed949b9999ea3418775f65826531

I will try to repro again, but from my previous testing on that other app the only way I could really repro it was keeping those overrides. After removing them, the error went away.

Hey this worked great; thank you @carlosantoniodasilva . Do you know if there is a way to regenerate a clean config/initializers/devise.rb file from the 4.9 package? I would like to make sure I'm running a clean copy. I couldn't find the source file in the repo, so is this automagically generated during Devise install?

Yes, I have removed all custom code.