diff --git a/ytypes/gnmi.go b/ytypes/gnmi.go index 5eea45830..52a463a3e 100644 --- a/ytypes/gnmi.go +++ b/ytypes/gnmi.go @@ -46,7 +46,9 @@ func UnmarshalNotifications(schema *Schema, ns []*gpb.Notification, opts ...Unma func UnmarshalSetRequest(schema *Schema, req *gpb.SetRequest, opts ...UnmarshalOpt) error { preferShadowPath := hasPreferShadowPath(opts) ignoreExtraFields := hasIgnoreExtraFields(opts) - + if req == nil { + return nil + } root := schema.Root node, nodeName, err := getOrCreateNode(schema.RootSchema(), root, req.Prefix, preferShadowPath) if err != nil { diff --git a/ytypes/gnmi_test.go b/ytypes/gnmi_test.go index 0a863d7fd..c5d7ef621 100644 --- a/ytypes/gnmi_test.go +++ b/ytypes/gnmi_test.go @@ -19,6 +19,15 @@ func TestUnmarshalSetRequest(t *testing.T) { want ygot.GoStruct wantErr bool }{{ + desc: "nil input", + inSchema: &Schema{ + Root: &ListElemStruct1{}, + SchemaTree: map[string]*yang.Entry{ + "ListElemStruct1": simpleSchema(), + }, + }, + want: &ListElemStruct1{}, + }, { desc: "updates to an empty struct", inSchema: &Schema{ Root: &ListElemStruct1{},