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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dirty attribute changes on update #1149

Merged
merged 7 commits into from
May 2, 2023

Conversation

nelsonwittwer
Copy link
Contributor

@nelsonwittwer nelsonwittwer commented Apr 28, 2023

Description

Fixes #1133 and #1037 which both report a substantial issue with tracking what attributes were actually modified by the user since the rest resources were initialized.

The root cause of this issue, as pointed out by @kaarelss, was symbols vs hashes when comparing drift on attributes 馃う . I also needed to 1) set associations in original_state since our API allows us to modify associated resources and 2) needed to ignore read only attributes in original_state.

How has this been tested?

  • Wrote a unit test that reproduced the issue. The fix was then applied to the base rest resource which passed the test.
  • In a local environment using this branch of the ruby API library, I found an existing product and updated a single attribute. I compared all other attributes and verified only the single attribute was modified.

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.

@nelsonwittwer nelsonwittwer changed the title Fix dirty attribute changes on update WIP Fix dirty attribute changes on update Apr 28, 2023
Copy link

@wayne692 wayne692 left a comment

Choose a reason for hiding this comment

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

It's easy

@nelsonwittwer nelsonwittwer changed the title WIP Fix dirty attribute changes on update Fix dirty attribute changes on update May 1, 2023
Copy link
Contributor

@paulomarg paulomarg 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!

@nelsonwittwer nelsonwittwer merged commit 9a7ef8a into main May 2, 2023
8 checks passed
@nelsonwittwer nelsonwittwer deleted the nelsonwittwer/fix_save_resources branch May 2, 2023 17:57
AnthonyRobertson17 added a commit that referenced this pull request May 10, 2023
AnthonyRobertson17 added a commit that referenced this pull request May 17, 2023
AnthonyRobertson17 added a commit that referenced this pull request May 18, 2023
AnthonyRobertson17 added a commit that referenced this pull request May 18, 2023
T.unsafe(@has_one[attr_sym]).create_instance(data: data_hash, session: session))
child = T.unsafe(@has_one[attr_sym]).create_instance(data: data_hash, session: session)
instance.public_send("#{attribute}=", child)
instance.original_state[attr_sym] = child.to_hash(true)
Copy link

@DuncanUszkay1 DuncanUszkay1 Jun 6, 2023

Choose a reason for hiding this comment

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

This was a breaking change for our application that went unreported in the changelog. We were creating an instance and immediately calling save on it, which with this change resulted in an empty hash being sent to Shopify (since the original state matched the current state after instantiation)

I.E. ShopifyAPI::ObjectName.build(attrs).save! <- this fails now AFAICT

Copy link

@DuncanUszkay1 DuncanUszkay1 Jun 6, 2023

Choose a reason for hiding this comment

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

Not sure if we were using the library improperly since I didn't see mention of this is the docs, but if not I can go update the changelog for others who might run into this. cc @nelsonwittwer

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.

Model save erroneously sends unchanged attributes to API
4 participants