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

Vault attribute changes are no longer detected in Rails 5.2 #85

Closed
jacferreira opened this issue Jul 26, 2019 · 4 comments
Closed

Vault attribute changes are no longer detected in Rails 5.2 #85

jacferreira opened this issue Jul 26, 2019 · 4 comments

Comments

@jacferreira
Copy link

With the changes made to ActiveRecord::Dirty 5.2 API, changed no longer returns the model changes on after_save callbacks. More info here: https://www.ombulabs.com/blog/rails/upgrades/active-record-5-1-api-changes.html

The proposed solution is to use saved_changes.keys instead changed but it seems that that won't work for virtual attributes. The only way I got it working was to use saved_change_to_attribute?.

If someone else wants to give their opinion on this that would be great, I'm willing to do the PR to fix this issue but would like for someone to confirm if this is the best solution.

@justincampbell
Copy link
Contributor

There are 2 PRs open for this, #67 and #76. Someone from HashiCorp will likely be spending time on this soon, but in the meantime if you have an opinion on which approach would be better going forward, that would be helpful. Thanks!

@jacferreira
Copy link
Author

I managed to make it work with saved_changes.keys but you have to register the vault attribute with the attributes API. Having the attributes API manage the vault attribute will ensure it will behave like a "real" model attribute and be picked up by the attribute changed methods.

The vault attribute is correctly identified as changed but the actual change was not returned (dob: [nil, nil]). This might be related to how the vault attribute is managed internally at the moment (using an instance variable) so I guess that this will probably be a more in-depth review than I was expecting.

@jacferreira
Copy link
Author

#67 makes more sense to me since it is registering the vault attribute against the attributes API and uses the new changed methods created for after_* callbacks while ensuring backwards compatibility with older Rails versions.

@Valarissa
Copy link
Contributor

I'm going to close this issue as those PRs have been merged and this issue should be fixed. Please let us know if this is not the case.

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

No branches or pull requests

3 participants