google-cloud-go
google-cloud-go copied to clipboard
fix(datastore): Ignore field mismatch errors
ErrFieldMismatch is returned when a field is to be loaded into a different type than the one it was stored from, or when a field is missing or unexported in the destination struct.
This PR allows user to suppress such errors. Some scenarios in which this would be useful are listed in https://github.com/googleapis/google-cloud-go/issues/913
Points to note
- Suppressing the error does not mean that Datastore will not fetch missing field. It just means that the field was still fetched from Datastore service but not loaded in user's struct.
- When writing the data back to Datastore, it will be overwritten. E.g.
If entity written to Datastore is
{X: 1, Y:2}
and it is loaded intotype NewStruct struct{X int}
, then{X:1}
is returned to the user. Now, if user modifies thisX = 5
and writes it back to Datastore, there will be no Y field left for this entity in Datastore.