go-shopify: Unable to nullify string attribute using the update function...

From @ckeyes88 on July 17, 2018 16:39

Currently, string values on any of the data structs have the omitempty tag associated with them. Because of this, if I try to set a string value to it’s nil value "", json.Unmarshal and json.Marshal leave off that attribute. This is a problem when trying to update a string field that I want to unset.

Steps to reproduce (using a variant as example):

  • Create a variant with v.InventoryManagement = "shopify"
  • Set v.InventoryManagement = ""
  • Call shopify.Variant.Updated(v)

Expected: The returned updated variant should have v.InventoryManagement == "" and that variant should no longer be set to have shopify track inventory.

Actual: The returned updated variant has v.InventoryManagement == "shopify" and that variant has no changes to it’s inventory management in the admin console.

Proposed fix: Convert the string values to string pointers so that they can be explicitly nil-able.

If I’m thinking about the problem incorrectly, I’d love some feedback on how to unset string properties.

Copied from original issue: getconversio/go-shopify#104

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 1
  • Comments: 16

Commits related to this issue

Most upvoted comments

Following up to echo the concerns here. This is an issue for us at Bold as well, as it can cause us two types of shortcomings:

  • inability to send ‘nil’ values of non-reference primitive datatypes via clients (cannot set ‘false’ of a bool, or ‘0’ of an int, etc.)
  • inability to clear / remove values via null on the JSON for non-nullable datatypes (cannot set null via string, etc.)

These two cases and combinations of them have caused various issues on our side and will need to be addressed as a part of the next major version due to the breaking nature of the fixes required.

For posterity, the solution we are weighing most towards is a mixture of pointers and nullable types based on the constraints on Shopify (nullable fields will use a nullable type, and fields where nil values are relevant will use a pointer. As much as the concerns about increasing complexity of the library are valid, this seems to be the cleanest and most usable approach out of those listed above without limiting the capabilities of the client.