-
Notifications
You must be signed in to change notification settings - Fork 257
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
Unable to nullify string attribute using the update function... #4
Comments
From @ckeyes88 on July 17, 2018 20:40 I can confirm that when I remove the |
From @ckeyes88 on July 19, 2018 17:10 Update: As a work around I used the custom data structure workflow to create a variant that didn't have the |
From @dlebech on July 19, 2018 18:43 @ckeyes88 thanks for the comments and sorry for the trouble. I haven't been using this feature for a while, but according to the documentation, it sounds like the
As such, I would be hesitant to remove the |
From @ckeyes88 on July 19, 2018 20:55 @dlebech Thanks for the response! I agree that it should not be set to Interested to hear your thoughts. |
From @dlebech on July 21, 2018 6:59 @ckeyes88 I see your point. When inventory management is initially unset, it will remain unset forever because of the If we removed Because of the support for partial updates, it feels like Would love to hear what others have to say about this. I think it's a bit of a conundrum, even though it seems very simple :) |
From @ckeyes88 on July 23, 2018 16:26 Ya the more I thought about it the more I realized it wasn't as simple as changing the How to determine if a JSON key has been set to null or not provided I suspect this is why, for example the AWS Golang sdk implements their own primitive datatypes Thanks again for your feedback/thoughts. |
From @ckeyes88 on July 23, 2018 17:5 Just adding some more reference information from an issue on the Go-Github sdk discussing the exact same problem and potential solutions. |
The complication with nullable fields and omit empty is applicable to other fields as well. For example, a variant update has a This seems to be a very old issue as mentioned here. Solutions to the problem are non-trivial and any suggestions are welcome. Some ideas that have been put forth include:
|
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:
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. |
Is the Stripe style method of handling nullable values the solution here? Stripe uses pointers to values, and then when constructing the struct you use For example: https://pkg.go.dev/github.com/stripe/stripe-go#ChargeParams and https://pkg.go.dev/github.com/stripe/stripe-go#String |
Yeah, that's a way to handle it. It's a massive change to the library, touching virtually every file and struct and all the tests, something I personally don't have time right now. So that's why I'm currently leaning towards "leave as is" and get the 4.0 release done to unblock releasing the recently merged changes. |
Oh yeah, its a huge breaking rewrite, I get it. The question of implementation also becomes, do you use |
Agreed on all points. Let me know if you're down to take on that larger rewrite and I'll hold off with the 4.0 release but I certainly don't have the time right now so in absence of someone stepping up I would just ship 4.0 without the nullable stuff. |
Ok, looks like it's not realistic to change all the fields for the upcoming 4.0 release. I opened #275 to make at least a few changes. So far this covers fields raised in #182 only. Any candidates from this thread that should be added? If yes please highlight which field exactly (a lot of field names are repeated in multiple places) and I'll make the change, otherwise we'll table this issue until 5.0 (or just close it). |
I believe there are quite a lot of fields which are affected but given they are not reported explicitly in issues for the project, i'd be fine if we just consider to idiomatically address it across the types in a future v5.0. We might be taking a step backwards in terms of usability if a subset of fields work in a different way. |
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'snil
value""
,json.Unmarshal
andjson.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):
v.InventoryManagement = "shopify"
v.InventoryManagement = ""
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#104
The text was updated successfully, but these errors were encountered: