Skip to content

Commit

Permalink
Do not pollute record changes when loading attributes for the first time
Browse files Browse the repository at this point in the history
This is done as in rails >= 5.2 the lock! & with_lock methods now
require that the record doesn't have any changes otherwise they'll raise
an error.

Apparently clear_attribute_changes receives an array of attributes which
it should clear.

https://apidock.com/rails/v5.2.3/ActiveModel/Dirty/clear_attribute_changes
  • Loading branch information
bliof-fc committed Oct 19, 2020
1 parent e905e36 commit 958ee5a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/vault/latest/encrypted_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def __vault_load_attribute!(attribute, options)
__vault_loaded_attributes << attribute

# Write the virtual attribute with the plaintext value
write_attribute(attribute, plaintext)
write_attribute(attribute, plaintext).tap { clear_attribute_changes([attribute]) }
end

# Encrypt all the attributes using Vault and set the encrypted values back
Expand Down

0 comments on commit 958ee5a

Please sign in to comment.