Skip to content

Commit

Permalink
[EventHubs] no-op instead of raising error when sending out empty eve…
Browse files Browse the repository at this point in the history
…nt 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 <76007337+swathipil@users.noreply.github.com>

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>
  • Loading branch information
yunhaoling and swathipil authored Feb 24, 2021
1 parent 264543c commit 1bfb95a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions sdk/eventhub/azure-eventhub/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 5.3.1 (Unreleased)

**Bug fixes**

- Sending empty `event_data_batch` will be a no-op now instead of raising error.

## 5.3.0 (2021-02-08)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ def send_batch(self, event_data_batch, **kwargs):
partition_id = (
to_send_batch._partition_id or ALL_PARTITIONS # pylint:disable=protected-access
)

if len(to_send_batch) == 0:
return

send_timeout = kwargs.pop("timeout", None)
try:
cast(EventHubProducer, self._producers[partition_id]).send(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ async def send_batch(
to_send_batch = await self.create_batch(partition_id=partition_id, partition_key=partition_key)
to_send_batch._load_events(event_data_batch) # pylint:disable=protected-access

if len(to_send_batch) == 0:
return

partition_id = (
to_send_batch._partition_id or ALL_PARTITIONS # pylint:disable=protected-access
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ async def test_send_with_partition_key_async(connstr_receivers):
data_val += 1
await client.send_batch(batch)

await client.send_batch(await client.create_batch())

found_partition_keys = {}
for index, partition in enumerate(receivers):
received = partition.receive_message_batch(timeout=5000)
Expand Down Expand Up @@ -202,8 +204,7 @@ async def test_send_list_partition_async(connstr_receivers):


@pytest.mark.parametrize("to_send, exception_type",
[([], EventDataSendError),
([EventData("A"*1024)]*1100, ValueError),
[([EventData("A"*1024)]*1100, ValueError),
("any str", AttributeError)
])
@pytest.mark.liveTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def test_send_with_partition_key(connstr_receivers):
data_val += 1
client.send_batch(batch)

client.send_batch(client.create_batch())

found_partition_keys = {}
for index, partition in enumerate(receivers):
received = partition.receive_message_batch(timeout=5000)
Expand Down Expand Up @@ -209,8 +211,7 @@ def test_send_list_partition(connstr_receivers):


@pytest.mark.parametrize("to_send, exception_type",
[([], EventDataSendError),
([EventData("A"*1024)]*1100, ValueError),
[([EventData("A"*1024)]*1100, ValueError),
("any str", AttributeError)
])
@pytest.mark.liveTest
Expand Down

0 comments on commit 1bfb95a

Please sign in to comment.