core/storage: fix nil data unmarshal (#4734)

This commit is contained in:
Caleb Doxsey 2023-11-10 13:16:22 -07:00 committed by GitHub
parent 15ca641b9c
commit d7ed62c350
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 17 deletions

View file

@ -126,13 +126,17 @@ func getNextChangedRecord(ctx context.Context, q querier, recordType string, aft
return nil, fmt.Errorf("error querying next changed record: %w", err)
}
a, err := protoutil.UnmarshalAnyJSON(data)
if isUnknownType(err) {
a = protoutil.ToAny(protoutil.ToStruct(map[string]string{
"id": recordID,
}))
} else if err != nil {
return nil, fmt.Errorf("error unmarshaling changed record data: %w", err)
// data may be nil if a record is deleted
var a *anypb.Any
if len(data) != 0 {
a, err = protoutil.UnmarshalAnyJSON(data)
if isUnknownType(err) {
a = protoutil.ToAny(protoutil.ToStruct(map[string]string{
"id": recordID,
}))
} else if err != nil {
return nil, fmt.Errorf("error unmarshaling changed record data: %w", err)
}
}
return &databroker.Record{