Skip to content

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

@alexsro

Description

@alexsro

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

  • Ruby [3.2]
  • Rails [7.0]
  • Devise [4.8.1]

Expected behavior

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions