Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions datastore/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,15 @@ func setVal(v reflect.Value, p Property) (s string) {
return fmt.Sprintf("%v is unsettable", v.Type())
}

rpValue := reflect.ValueOf(pValue)
if !rpValue.Type().AssignableTo(v.Type()) {
return fmt.Sprintf("%q is not assignable to %q", rpValue.Type(), v.Type())
if pValue == nil {
v.Set(reflect.Zero(v.Type()))
Comment thread
bhshkh marked this conversation as resolved.
Resolved
} else {
rpValue := reflect.ValueOf(pValue)
if !rpValue.Type().AssignableTo(v.Type()) {
return fmt.Sprintf("%q is not assignable to %q", rpValue.Type(), v.Type())
}
v.Set(rpValue)
}
v.Set(rpValue)

case reflect.Ptr:
// v must be a pointer to either a Key, an Entity, or one of the supported basic types.
Expand Down
17 changes: 17 additions & 0 deletions datastore/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,23 @@ func TestLoadNull(t *testing.T) {
}
}

func TestLoadNilInterface(t *testing.T) {
Comment thread
bhshkh marked this conversation as resolved.
Resolved
type WithAny struct {
AnyField interface{}
}

withAny1 := &WithAny{}
err := loadEntityProto(withAny1, &pb.Entity{
Key: keyToProto(testKey0),
Properties: map[string]*pb.Value{
"AnyField": {ValueType: &pb.Value_NullValue{}},
},
})
if err != nil {
t.Fatalf("got: %v, want: nil", err)
}
Comment thread
bhshkh marked this conversation as resolved.
Resolved
}

type KeyLoaderEnt struct {
A int
K *Key
Expand Down
⌂ 换网址