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

Error when using find_or_initialize_with_errors method with required_attributes as a symbol #5588

Open alexsro opened 1 year ago

alexsro commented 1 year ago

Pre-check

I'm facing an issue when trying to use the find_or_initialize_with_errors method from Devise with the required_attributes parameter as a symbol. When I use the symbol as the value for the required_attributes parameter, the method fails to properly retrieve the keys from the hash and returns an empty hash, resulting in an exception.

This issue occurs when the reset_password_by_token method from Devise's Recoverable module is called in the PasswordController. The reset_password_by_token method calls find_or_initialize_with_errors_by with the required_attributes parameter as a symbol, causing the method to fail.

Upon investigating the issue, I realized that the method tries to transform the attributes parameter into a hash with indifferent keys using the with_indifferent_access method. However, when required_attributes is a symbol, the slice method fails to properly retrieve the keys from the hash, resulting in an empty hash.

To work around the issue, I used the required_attributes parameter as an array of strings. However, I believe the method should work properly with the required_attributes parameter as a symbol.

Thanks.

Environment

Expected behavior

I believe the method should work properly with the required_attributes parameter as a symbol.