-
Notifications
You must be signed in to change notification settings - Fork 474
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
Comments
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. |
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. |
Hello! Found same issue here with Product. When we are trying to save object without changes (
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. |
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 theput
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:
save
. Maybe something likesave(only_changed: false)
save
call if we want. Something likechanged?
ordirty?
maybe?It would also be great if an error or warning of some sort was returned if the payload you are submitting is empty.
The text was updated successfully, but these errors were encountered: