devise icon indicating copy to clipboard operation
devise copied to clipboard

NoMethodError when finding user after Rails 7.2 upgrade.

Open knirirr opened this issue 1 year ago • 3 comments

  • Ruby 3.2.2
  • Rails 7.2.0
  • Devise 4.9.4

Following the upgrade, this code from app/models/user.rb:89:in 'find_for_database_authentication' triggers a NoMethodError:

 def self.find_for_database_authentication(warden_conditions)
    conditions = warden_conditions.dup
    login = conditions[:login]
    where(['lower(username) = :value OR lower(email) = :value', { value: login.downcase.strip }]).first if login  # NoMethodError thrown here
  end

The error:

NoMethodError (undefined method `name' for "john":String):

(i.e. this is the user's username).

Previously I was using Rails 7.1.3.3 and reverting to that fixes this issue (7.1.3.4 is fine as well). I can't upgrade to the latest master of Devise due to also using devise-jwt.

Strangely, this problem only affects the application when running in development mode.

knirirr avatar Aug 21 '24 13:08 knirirr

@knirirr hey, could you please provide a sample app that reproduces this issue?

nashby avatar Aug 21 '24 16:08 nashby

@knirirr hey, could you please provide a sample app that reproduces this issue?

Unfortunately not; I have not been able to reproduce it with a new app, but I can consistently do so on the old one (as can other developers in the team). Looking at the stack trace again it appears to start in the sessions_controller:

  def create
    resource = warden.authenticate!(auth_options)  
    ...

I would happily investigate this but after looking at the relevant part of the warden gem I'm none the wiser. Do you have any suggestions?

knirirr avatar Aug 22 '24 09:08 knirirr

Well, I've had no luck finding what's going on, and so have resorted to "fixing" it with this code, in config/initializers/rails_7_2_dev_login_fix.rb

class String
  def name
    self
  end
end

class Integer
  def name
    self
  end
end

knirirr avatar Aug 27 '24 15:08 knirirr

Alright, looks like it's not a devise issue, so closing this. Feel free to ping us if you're able to reproduce it in a sample application. Thanks!

nashby avatar Sep 01 '24 14:09 nashby

I have upgraded rails 6.1 to 7.2. I am getting error .rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require': cannot load such file -- devise_helper (LoadError)

raju-ps avatar Feb 12 '25 06:02 raju-ps