Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EventHubs] no-op instead of raising error when sending out empty event data batch #16638

Merged
merged 8 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 emtpy `event_data_batch` will be a no-op now instead of raising error.
yunhaoling marked this conversation as resolved.
Show resolved Hide resolved

## 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