Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encrypted attributes improperly casted #1836

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Michaelvilleneuve
Copy link

This PR fixes a bug introduced by ActiveRecord::Encrypted attributes.
Instead of returning a ActiveModel::Type::String like they used to, encrypted attributes return an instance of ActiveRecord::Encryption::EncryptedAttributeType, on which you need to call #cast_type in order to obtain the original type.

To fix this, I check whether or not the attribute #responds_to?(:cast_type) which would indicate that we need to take into account the underlying type instead of just #type_for_attribute.

Checking this instead of checking if the attribute_name #responds_to?(:encrypted_attributes) allows to take into account other forms of type overriding that ActiveRecord may introduce in the future or potentially already exist.

See the type difference below between a regular string attribute and an encrypted attribute
image

Fixes #1829

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Encrypted attributes always default to textarea
1 participant