From a2f85225f3eb37f51bc6fe945db1c6189a14c7d4 Mon Sep 17 00:00:00 2001 From: Will Baker Date: Thu, 21 Nov 2024 09:53:29 -0500 Subject: [PATCH] materialize-mongodb: don't send a batch if there were 0 documents When setting a `notBefore` configuration there will be transactions with 0 stored documents. This adds a condition to prevent a panic trying to send a batch in Store when there aren't any documents to store. --- materialize-mongodb/transactor.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/materialize-mongodb/transactor.go b/materialize-mongodb/transactor.go index 54412ac9ed..5079ea3c34 100644 --- a/materialize-mongodb/transactor.go +++ b/materialize-mongodb/transactor.go @@ -180,8 +180,10 @@ func (t *transactor) Store(it *m.StoreIterator) (m.StartCommitFunc, error) { } // Drain the last batch. - if err := sendBatch(); err != nil { - return nil, err + if len(batch) > 0 { + if err := sendBatch(); err != nil { + return nil, err + } } close(sendBatches)