Skip to content

Commit 6ac5d85

Browse files
authored
fix: empty raw bytes handling during cdc (#4125)
previously we were decoding bson.D so nil check on change event key/document is sufficient. with #4093, we made a change where `fullDocument` is bson.Raw, and before decoding we are running nil check, which is now a byte slice. Checking `len(fullDocument) > 0` instead of `fullDocument != nil` fixes this and covers both nil and empty slice cases.
1 parent b70961b commit 6ac5d85

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

flow/connectors/mongo/cdc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (c *MongoConnector) PullRecords(
220220
return fmt.Errorf("failed to create converter: %w", err)
221221
}
222222
addRecordItems := func(documentKey bson.Raw, fullDocument bson.Raw, items *model.RecordItems, tableName string) error {
223-
if documentKey != nil {
223+
if len(documentKey) > 0 {
224224
rv := documentKey.Lookup(DefaultDocumentKeyColumnName)
225225
if rv.IsZero() || rv.Type == bson.TypeNull {
226226
return exceptions.NewInvalidIdValueError(tableName)
@@ -234,7 +234,7 @@ func (c *MongoConnector) PullRecords(
234234
return fmt.Errorf("document key is nil")
235235
}
236236

237-
if fullDocument != nil {
237+
if len(fullDocument) > 0 {
238238
qValue, err := converter.QValueJSONFromDocument(fullDocument)
239239
if err != nil {
240240
return fmt.Errorf("failed to convert document: %w", err)

0 commit comments

Comments
 (0)