Shopify / shopify-api-ruby

ShopifyAPI is a lightweight gem for accessing the Shopify admin REST and GraphQL web services.
MIT License
1.06k stars 473 forks source link

Shopify Product `tags` format is inconsistent between GET and POST #1173

Open fmichaut-diff opened 1 year ago

fmichaut-diff commented 1 year ago

Issue summary

When we access product.tags it returns a string of comma separated tags. When we save the product, it is required to set the tags to an array of tags.

This means that fetching a product and saving it without touching the tags results in an error :

product_id = XXX
ShopifyAPI::Auth::Session.temp(...) do 
  shopify_product = ShopifyAPI::Product.find(id: product_id)
  # shopify_product.tags = shopify_product.tags.split(', ') # Uncomment this to fix the call
  shopify_product.save!
end

# -> /usr/local/bundle/gems/shopify_api-13.0.0/lib/shopify_api/clients/http_client.rb:71:in `request': {"errors":{"product":"Required parameter missing or invalid"},"error_reference":"If you report this error, please include this id: f610c13a-c4ec-449d-b33f-1204e1eb2c3b."} (ShopifyAPI::Errors::HttpResponseError)

Expected behavior

The object returned by find or similar fetching methods should be in a state where they can be saved without the user having to map some fields (that he might not even be touching) in a different format.

Actual behavior

If you don't map the tags field from string to array, you can't save the product.

Steps to reproduce the problem

  1. Use the given code to reproduce the issue
  2. Notice that uncomenting the line makes the error go away
github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

fmichaut-diff commented 1 year ago

Not stale

jaredbeck commented 1 year ago

I can reproduce this issue in 13.1.0,

product = shop.execute_shopify_api { ShopifyAPI::Product.find(id: 7084933120074) }
product.tags #=> "foo"
product.save
# shopify_api-13.1.0/lib/shopify_api/clients/http_client.rb:71:
# in `request': {"errors":{"product":"Required parameter missing or invalid"},
# "error_reference":"If you report this error, please include this id: 7f494072-d3f9-46ce-ac60-60a5848feed8."} 
# (ShopifyAPI::Errors::HttpResponseError) 

product.tags = ['foo']
product.save # success
jaredbeck commented 1 year ago

The ShopifyAPI::Order object has a very similar issue with tags (perhaps exactly the same issue). It is reproducible in 13.1.0 using the same steps.