Skip to content

Commit 1bfb95a

Browse files
[EventHubs] no-op instead of raising error when sending out empty event data batch (#16638)
* better error message * remove extra blank line * should be a no-op instead of raising error * update changelog * fix pylint * fix pytest * fix async test * Update sdk/eventhub/azure-eventhub/CHANGELOG.md Co-authored-by: swathipil <[email protected]> Co-authored-by: swathipil <[email protected]>
1 parent 264543c commit 1bfb95a

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

sdk/eventhub/azure-eventhub/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 5.3.1 (Unreleased)
44

5+
**Bug fixes**
6+
7+
- Sending empty `event_data_batch` will be a no-op now instead of raising error.
58

69
## 5.3.0 (2021-02-08)
710

sdk/eventhub/azure-eventhub/azure/eventhub/_producer_client.py

+4
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ def send_batch(self, event_data_batch, **kwargs):
255255
partition_id = (
256256
to_send_batch._partition_id or ALL_PARTITIONS # pylint:disable=protected-access
257257
)
258+
259+
if len(to_send_batch) == 0:
260+
return
261+
258262
send_timeout = kwargs.pop("timeout", None)
259263
try:
260264
cast(EventHubProducer, self._producers[partition_id]).send(

sdk/eventhub/azure-eventhub/azure/eventhub/aio/_producer_client_async.py

+3
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ async def send_batch(
284284
to_send_batch = await self.create_batch(partition_id=partition_id, partition_key=partition_key)
285285
to_send_batch._load_events(event_data_batch) # pylint:disable=protected-access
286286

287+
if len(to_send_batch) == 0:
288+
return
289+
287290
partition_id = (
288291
to_send_batch._partition_id or ALL_PARTITIONS # pylint:disable=protected-access
289292
)

sdk/eventhub/azure-eventhub/tests/livetest/asynctests/test_send_async.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ async def test_send_with_partition_key_async(connstr_receivers):
3030
data_val += 1
3131
await client.send_batch(batch)
3232

33+
await client.send_batch(await client.create_batch())
34+
3335
found_partition_keys = {}
3436
for index, partition in enumerate(receivers):
3537
received = partition.receive_message_batch(timeout=5000)
@@ -202,8 +204,7 @@ async def test_send_list_partition_async(connstr_receivers):
202204

203205

204206
@pytest.mark.parametrize("to_send, exception_type",
205-
[([], EventDataSendError),
206-
([EventData("A"*1024)]*1100, ValueError),
207+
[([EventData("A"*1024)]*1100, ValueError),
207208
("any str", AttributeError)
208209
])
209210
@pytest.mark.liveTest

sdk/eventhub/azure-eventhub/tests/livetest/synctests/test_send.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def test_send_with_partition_key(connstr_receivers):
2828
data_val += 1
2929
client.send_batch(batch)
3030

31+
client.send_batch(client.create_batch())
32+
3133
found_partition_keys = {}
3234
for index, partition in enumerate(receivers):
3335
received = partition.receive_message_batch(timeout=5000)
@@ -209,8 +211,7 @@ def test_send_list_partition(connstr_receivers):
209211

210212

211213
@pytest.mark.parametrize("to_send, exception_type",
212-
[([], EventDataSendError),
213-
([EventData("A"*1024)]*1100, ValueError),
214+
[([EventData("A"*1024)]*1100, ValueError),
214215
("any str", AttributeError)
215216
])
216217
@pytest.mark.liveTest

0 commit comments

Comments
 (0)