NoMethodError when finding user after Rails 7.2 upgrade.
- 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 hey, could you please provide a sample app that reproduces this issue?
@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?
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
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!
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)