Allow for empty transactional batch without exception
See original GitHub issueIs your feature request related to a problem? Please describe. When running a transactional batch, if there are no operations in the batch, ExecuteAsync throws an exception. This is less than ideal because in scenarios where there are between 0 and N valid operations it means tracking a flag to determine if ExecuteAsync should be called. An example of this is an event processor that looks for all items related to the event and updates them in a batch. In some instances the event might not pertain to any items so the batch will have 0 operations. In this instance I would expect ExecuteAsync to simply return as successful with 0 operations.
Describe the solution you’d like Change the default behavior of TransactionalBatch to return a TransactionalBatchResponse with an empty result set without performing any network I/O when there are no operations
Describe alternatives you’ve considered
- Allow for a transactional batch option in a method overload that does not throw when performing a transaction batch with 0 operations
- Expose a public OperationCount property on TransactionalBatch so users can do something like:
if (batch.OperationCount == 0)
{
return;
}
await batch.ExecuteAsync()
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (8 by maintainers)
Top GitHub Comments
Would exposing a method to get the number of items in the batch currently be a good option? That way an additional flag is not needed.
My concern with supporting an empty list is in most scenarios that seems like a bug in the application logic. It might cause more confusion because users will think they are sending items. The SDK returns a success, but that’s because they didn’t add any items to the batch.
I would be fine with this as a resolution - this makes the check a simple one right before executing the batch, instead of having to track throughout the code as operations are added.