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

Suggestion: Make it easier to identify or bypass only submitting dirty attributes on update #1227

Open
jduff opened this issue Oct 6, 2023 · 3 comments

Comments

@jduff
Copy link
Contributor

jduff commented Oct 6, 2023

This feature to only send changed fields has tripped me up a few times and can be difficult to identify.

The problem I've ran into is when the object state hasn't changed and you call save it will still do the put request with an empty payload and you end up with an error with something like {"errors":{"metafield":"Required parameter missing or invalid"} which isn't very clear about the problem. As far as I can tell there isn't a method that I can use to inspect the object to decide if I need to save or not.

If this functionality is really important what do you think about a few additional features to make it easier to work with or bypass, such as:

  1. Allow bypassing the dirty attributes check and sending all attributes on save. Maybe something like save(only_changed: false)
  2. Provide a method that we can use to inspect the object to see if there are changes so we can skip the save call if we want. Something like changed? or dirty? maybe?

It would also be great if an error or warning of some sort was returned if the payload you are submitting is empty.

@paulomarg
Copy link
Contributor

Hey, thanks for raising this! I agree that this is something we could do, so we'll look into it.

I think this should work, but I'd like to test it before we commit to making the change, so it might be a while until we can do this.

@jrubaloff
Copy link

This one hung us up too. We had to write our own "did anything change" code to compare each attribute before actually calling save. I've never had an API fail in this scenario. Very odd. Lots of ways to fix this on the API side. It's been 4 months. Hope the fix comes soon. Thanks.

@unrooty
Copy link

unrooty commented Mar 20, 2024

Hello! Found same issue here with Product. When we are trying to save object without changes (Product in our case) then we receive the following error:

ShopifyAPI::Errors::HttpResponseError ({"errors":{"product":"Required parameter missing or invalid"},"error_reference":"If you report this error, please include this id: ID."})

Here is code example

shop = Shop.find_by(shopify_domain: 'test.myshopify.com')

product = ShopifyAPI::Auth::Session.temp(shop: shop.shopify_domain, access_token: shop.oauth_token) do
  ShopifyAPI::Product.find(id: 1)
end

product.save! # => outputs `ShopifyAPI::Errors::HttpResponseError` provided below

So it will send empty payload. It is required to set at least 1 even unknown attribute to force object to send payload.

shop = Shop.find_by(shopify_domain: 'test.myshopify.com')

product = ShopifyAPI::Auth::Session.temp(shop: shop.shopify_domain, access_token: shop.oauth_token) do
  ShopifyAPI::Product.find(id: 1)
end

product.unknown = nil

product.save! # => `T::Private::Types::Void::VOID` which is expected after successful save.

The main question is.

Is there any normal workaround or way to force objects to use attributes even if nothing changed?

Or are there any plans to change this behaviour? I could try to help with it if not.

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

4 participants