allow lazy decrypted vault attributes to be referenced after a destroy #110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After destroying a record, ActiveRecord marks the in-memory object as frozen and unable to be altered. This was fine in older versions of Rails prior to the attributes API, and it's mostly fine now. However, if lazy decrypt is enabled and you need to access an encrypted attribute after the destroy happens -- for instance, as part of a
dependent: :destroy
chain -- vault-rails attempts to set the plaintext attribute on the frozen object, raising a "Can't modify frozen hash" error.As a workaround, this PR ensures that attributes are decrypted before a destroy so the plain text values can be accessed by after-destroy hooks if needed.
Currently, I've set this as universal behavior, since being able to access encrypted attributes after a destroy was the default prior to #67. However, another possibility would be only enabling this behavior for specific attributes, via something along these lines: