I have been facing this strange issue on production in Rails console: rails c -e production, where trying to fetch the user: User.first results in the following error:
2.7.2 :005 > User.first
Traceback (most recent call last):
ArgumentError (wrong number of arguments (given 0, expected 1))
Nothing can be figured out from this error. For some reason, it happens only with this user model, for rest of the models, everything is working fine.
Also, this error does not appear locally either in development or production mode.
Attaching the user model here, for reference:
# frozen_string_literal: true
class User < ApplicationRecord
devise :database_authenticatable,
:registerable,
:recoverable,
:rememberable,
:trackable,
:confirmable,
:omniauthable,
:validatable
....
end
Any pointers to solving this issue will be highly appreciated.
Update
On further investigation and some help from chatGPT, I figured that the devise' database_authenticable method in the cause of the error. On removing it, everything is working fine.
Now I need to figure out why that method is throwing the error.
Alright so the issue was that
database_authenticablemodule has a method namedpassword_digestwhich accepts an argument and hashes the password using bcrypt.Now, I had an existing
password_digestcolumn in the database which was required by ActiveRecords'shas_secure_passwordthat I was using earlier. So that method was being called without arguments and hence throwing the error:ArgumentError (wrong number of arguments (given 0, expected 1)).I had a migration to remove the
password_digestcolumn but apparently it failed at some point of time and I had to remove the column to make things work.I hope it helps anyone facing a similar issue.