google-cloud-go icon indicating copy to clipboard operation
google-cloud-go copied to clipboard

fix(datastore): Ignore field mismatch errors

Open bhshkh opened this issue 1 year ago • 0 comments

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

  1. 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.
  2. 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 into type NewStruct struct{X int}, then {X:1} is returned to the user. Now, if user modifies this X = 5 and writes it back to Datastore, there will be no Y field left for this entity in Datastore.

bhshkh avatar Oct 12 '23 08:10 bhshkh