Skip to content

Commit

Permalink
[Service Bus]Match the partition key with session id only when both a…
Browse files Browse the repository at this point in the history
…re set (#19233)

The azure documentation says "if a message has the partition key property but not the session ID property set, then Service Bus uses the partition key property value as the partition key. If the message has both the session ID and the partition key properties set, both properties must be identical" [https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-partitioning#using-a-partition-key]. 
[Re-raised #18955]
  • Loading branch information
bishnu-shb authored Jun 22, 2021
1 parent 9df4984 commit 3072fc8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
6 changes: 6 additions & 0 deletions sdk/servicebus/azure-servicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 7.3.1 (Unreleased)

**Bug Fixes**

* Fixed a bug that when setting `ServiceBusMessage.partition_key`, input value should be not validated against `session_id` of None (PR #19233, thanks @bishnu-shb).

## 7.3.0 (2021-06-08)

**New Features**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def partition_key(self, value):
)
)

if value and value != self.session_id:
if value and self.session_id and value != self.session_id:
raise ValueError(
"partition_key:{} cannot be set to a different value than session_id:{}".format(
value, self.session_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Licensed under the MIT License.
# ------------------------------------

VERSION = "7.3.0"
VERSION = "7.3.1"
6 changes: 2 additions & 4 deletions sdk/servicebus/azure-servicebus/tests/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ def test_queue_by_queue_client_conn_str_receive_handler_peeklock(self, servicebu
message.content_type = 'application/text'
message.correlation_id = 'cid'
message.message_id = str(i)
with pytest.raises(ValueError):
message.partition_key = 'pk'
message.partition_key = 'pk'
message.to = 'to'
message.reply_to = 'reply_to'
sender.send_messages(message)
Expand Down Expand Up @@ -216,8 +215,7 @@ def test_queue_by_queue_client_send_multiple_messages(self, servicebus_namespace
messages = []
for i in range(10):
message = ServiceBusMessage("Handler message no. {}".format(i))
with pytest.raises(ValueError):
message.partition_key = 'pkey'
message.partition_key = 'pkey'
message.time_to_live = timedelta(seconds=60)
message.scheduled_enqueue_time_utc = utc_now() + timedelta(seconds=60)
message.partition_key = None
Expand Down
3 changes: 1 addition & 2 deletions sdk/servicebus/azure-servicebus/tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def test_session_by_session_client_conn_str_receive_handler_peeklock(self, servi
for i in range(3):
message = ServiceBusMessage("Handler message no. {}".format(i))

with pytest.raises(ValueError):
message.partition_key = 'pkey'
message.partition_key = 'pkey'

message.session_id = session_id
message.partition_key = session_id
Expand Down

0 comments on commit 3072fc8

Please sign in to comment.