question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow for empty transactional batch without exception

See original GitHub issue

Is 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:open
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
j82wcommented, Dec 1, 2021

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.

1reaction
ssa3512commented, Dec 1, 2021

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.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid empty transaction entity from being persisted?
You can do this by using the transaction log to “replay” transactions into a new system.
Read more >
Spring-Batch without persisting metadata to database?
Simply create a configuration without datasource for Batch configuration : @Configuration @EnableAutoConfiguration @EnableBatchProcessing ...
Read more >
Configuring Skip Logic in Spring Batch
With the above configuration, we instruct Spring Batch framework to skip on any Exception (within a configured limit) except SAXException. This ...
Read more >
TransactionalBatch.ExecuteAsync doesn't support retries
Call TransactionalBatch.ExecuteAsync over a flakey network connection. If it fails due to a network error, call TransactionalBatch.
Read more >
Leveraging Transactional Batch in Cosmos DB with the ...
A batch can include create, read, update, and delete operations, among others, on items in a container.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found