Skip to content

Commit e4be937

Browse files
authored
[1.15 FIX] Ignore 404 errors in transactional cosmos delete operations (#3893)
Signed-off-by: Albert Callarisa <[email protected]>
1 parent e05400c commit e4be937

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

state/azure/cosmosdb/cosmosdb.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,14 +567,27 @@ func (c *StateStore) Multi(ctx context.Context, request *state.TransactionalStat
567567
}
568568

569569
if !batchResponse.Success {
570-
// Transaction failed, look for the offending operation
570+
var transactionError error
571+
571572
for index, operation := range batchResponse.OperationResults {
573+
// delete operations with no etag check are allowed to fail with a 404
574+
deleteReq, isDelete := request.Operations[index].(state.DeleteRequest)
575+
if isDelete && operation.StatusCode == http.StatusNotFound && !deleteReq.HasETag() {
576+
continue
577+
}
578+
572579
if operation.StatusCode != http.StatusFailedDependency {
573580
c.logger.Errorf("Transaction failed due to operation %v which failed with status code %d", index, operation.StatusCode)
574581
return fmt.Errorf("transaction failed due to operation %v which failed with status code %d", index, operation.StatusCode)
575582
}
583+
transactionError = errors.New("transaction failed")
584+
}
585+
586+
// If all errors are from delete operations with a 404 (and no etag check), we end up here with a nil error.
587+
// This is expected, as we allow delete operations to fail with a 404.
588+
if transactionError != nil {
589+
return transactionError
576590
}
577-
return errors.New("transaction failed")
578591
}
579592

580593
// Transaction succeeded

0 commit comments

Comments
 (0)