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

Model ID not updated after calling save() #1148

Closed key88sf closed 1 year ago

key88sf commented 1 year ago

Issue summary

For any of the ShopifyAPI models, for example ShopifyAPI::Fulfillment, ShopifyAPI::PriceRule, etc, when creating them with the SDK and calling the .save method, the 'id' attribute is not updated. So after saving, trying to find the ID of the newly saved record is not possible.

For example:

fulfillment = ShopifyAPI::Fulfillment.new(session: ...)
fulfillment.status = "success"
# set other attributes ...

fulfillment.save  # successful save of new fulfillment

puts fulfillment.id # ==> nil    :(  :( :(

Expected behavior

After successfully creating a ShopifyAPI object, the .id property should be set to the newly created ID of the object in Shopify.

Actual behavior

No value is set and nil is returned when accessing the ID.

key88sf commented 1 year ago

Looks like you need to call save! and not save for this to work. Hope this helps someone else 👍