From 0102c00571dd9022ec05728258865e6452734df1 Mon Sep 17 00:00:00 2001 From: Bishnu Choudhury Date: Wed, 26 May 2021 13:29:39 +0530 Subject: [PATCH 1/4] Match the partition key with session id only when both are set 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]. --- .../azure-servicebus/azure/servicebus/_common/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py index 5bd423442e7a..f5ed0ace07cf 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py @@ -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 From c5cd407cce1c4715f326afffb1f189390fc01700 Mon Sep 17 00:00:00 2001 From: Swathi Pillalamarri Date: Mon, 14 Jun 2021 16:07:22 -0700 Subject: [PATCH 2/4] fix tests --- sdk/servicebus/azure-servicebus/tests/test_queues.py | 6 ++---- sdk/servicebus/azure-servicebus/tests/test_sessions.py | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/tests/test_queues.py b/sdk/servicebus/azure-servicebus/tests/test_queues.py index 1cfdc9bee017..9f9f837d38ff 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_queues.py +++ b/sdk/servicebus/azure-servicebus/tests/test_queues.py @@ -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) @@ -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 diff --git a/sdk/servicebus/azure-servicebus/tests/test_sessions.py b/sdk/servicebus/azure-servicebus/tests/test_sessions.py index 75bd1edf3e44..6250367b0b20 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_sessions.py +++ b/sdk/servicebus/azure-servicebus/tests/test_sessions.py @@ -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 From 5b11da7b63d7b2d40416e2c96c153184a490377b Mon Sep 17 00:00:00 2001 From: Swathi Pillalamarri Date: Tue, 15 Jun 2021 12:50:50 -0700 Subject: [PATCH 3/4] update changelog --- sdk/servicebus/azure-servicebus/CHANGELOG.md | 6 ++++++ .../azure-servicebus/azure/servicebus/_version.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/CHANGELOG.md b/sdk/servicebus/azure-servicebus/CHANGELOG.md index 8c87776e8a23..f5595c22ba07 100644 --- a/sdk/servicebus/azure-servicebus/CHANGELOG.md +++ b/sdk/servicebus/azure-servicebus/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 7.3.1 (Unreleased) + +**Bug Fixes** + +* Fixed a bug when setting the `partition_key` on `ServiceBusMessage` that should ensure that the session ID has been set before checking that the value passed in is equivalent to the session ID (PR #19233, thanks @bishnu-shb). + ## 7.3.0 (2021-06-08) **New Features** diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_version.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_version.py index 18ac64a0a1a3..7efc5dfb5363 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_version.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_version.py @@ -3,4 +3,4 @@ # Licensed under the MIT License. # ------------------------------------ -VERSION = "7.3.0" +VERSION = "7.3.1" From 444d4ee44a0ea4872a5b8fe5193a3428f88c539b Mon Sep 17 00:00:00 2001 From: Swathi Pillalamarri Date: Thu, 17 Jun 2021 11:43:51 -0700 Subject: [PATCH 4/4] update changelog --- sdk/servicebus/azure-servicebus/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/CHANGELOG.md b/sdk/servicebus/azure-servicebus/CHANGELOG.md index f5595c22ba07..c523940f080b 100644 --- a/sdk/servicebus/azure-servicebus/CHANGELOG.md +++ b/sdk/servicebus/azure-servicebus/CHANGELOG.md @@ -4,7 +4,7 @@ **Bug Fixes** -* Fixed a bug when setting the `partition_key` on `ServiceBusMessage` that should ensure that the session ID has been set before checking that the value passed in is equivalent to the session ID (PR #19233, thanks @bishnu-shb). +* 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)