Open dmotylev opened 1 year ago
(Wow, great repro snippet @dmotylev . Thanks!)
Not saving empty slice is expected behaviour of omitempty, but removing empty values from the slice is not. Perhaps it is an another issue
I agree that this is a separate issue, and it has bitten us at Khan Academy as well. I see this code in https://github.com/googleapis/google-cloud-go/blob/9799e024c6e12a7df694fe68f3f0a539d519ee1b/datastore/save.go#L120:
// When we recurse on the derefenced pointer, omitempty no longer applies:
// we already know the pointer is not empty, it doesn't matter if its referent
// is empty or not.
opts.omitEmpty = false
It seems to me that the same logic should apply to slices: omitempty
on a slice means (to me anyway) "do not store the slice if it's the empty slice", not "discard all zero values inside the slide." So the code should be setting opts.omitEmpty in saveSliceProperty
.
(Of course, that's a breaking change and may not be safe to make at this point. :-( )
Possible fix added in private repository https://github.com/bhshkh/google-cloud-go/pull/4 . Needs more testing. Will pick up later
Client
Datastore
Environment
MacOS
Go Environment
$ go version
$ go env
Code
Expected behavior
The datastore put method should allow the mixing of empty and non-empty values in the array in any order.
Actual behavior
It does not allow any non-empty value if the first value is empty.
Additional context
Tested with version 1.0.0 and 1.9.0
P.S.
Not saving empty slice is expected behaviour of
omitempty
, but removing empty values from the slice is not. Perhaps it is an another issue