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

Ignore read-only attributes when updating through REST resources #1157

Conversation

AnthonyRobertson17
Copy link
Contributor

@AnthonyRobertson17 AnthonyRobertson17 commented May 16, 2023

Description

Follow up on the changes in this PR #1149. When a resource has read-only attributes and you attempt to call save, the update payload would contain an erroneous entry for the read-only attributes with the value of HashDiff::NO_VALUE.

The root cause of this issue is that the original_state contains the read-only attributes, however the lookup of the current resource state with to_hash(true) strips them out. Performing a left_diff hash comparison then yields the resulting HashDiff::NO_VALUE.

The fix I've implemented is to use a copy of the original_state hash with read-only attributes removed when performing the comparison to see which attributes to update.

How has this been tested?

I've written a new unit test for the base resource and verified it failed as expected prior to implementing the fix.

Checklist:

  • My commit message follow the pattern described in here
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have updated the project documentation.
  • I have added a changelog line.

Copy link

@rtymchyk rtymchyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me :)

@AnthonyRobertson17 AnthonyRobertson17 merged commit fca16f1 into main May 18, 2023
8 checks passed
@AnthonyRobertson17 AnthonyRobertson17 deleted the AnthonyRoberton17/fix-saving-resources-with-readonly-attributes branch May 18, 2023 15:13
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

Successfully merging this pull request may close these issues.

None yet

3 participants