From 7c76eb77895bfd704a4a29c49d98a42fd364f84b Mon Sep 17 00:00:00 2001 From: Victoria Hall Date: Mon, 27 Oct 2025 14:57:57 -0500 Subject: [PATCH 1/2] fix delivery count --- CODEOWNERS | 2 +- .../extensions/bindings/servicebus/utils.py | 5 ++-- .../tests/test_servicebus.py | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index a17f9cc..fd28d26 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -9,4 +9,4 @@ # AZURE FUNCTIONS TEAM # For all file changes, github would automatically # include the following people in the PRs. -* @vrdmr @gavin-aguiar @hallvictoria @EvanR-Dev +* @vrdmr @gavin-aguiar @hallvictoria diff --git a/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py b/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py index c240e6a..52316e9 100644 --- a/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py +++ b/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py @@ -8,6 +8,7 @@ _X_OPT_LOCK_TOKEN = b"x-opt-lock-token" +LOCK_TOKEN_LENGTH = 16 # AMQP format codes (subset) FMT_NULL = 0x40 @@ -30,7 +31,7 @@ def get_lock_token(message: bytes, index: int) -> str: # Convert the lock token to a UUID using the first 16 bytes # Use little-endian to match SDK - lock_token_uuid = uuid.UUID(bytes_le=lock_token_encoded[:16]) + lock_token_uuid = uuid.UUID(bytes_le=lock_token_encoded[:LOCK_TOKEN_LENGTH]) return lock_token_uuid @@ -40,7 +41,7 @@ def get_amqp_message(message: bytes, index: int): Get the amqp message from the model_binding_data content and create the message. """ - amqp_message = message[index + len(_X_OPT_LOCK_TOKEN):] + amqp_message = message[LOCK_TOKEN_LENGTH:] decoded_message = uamqp.Message().decode_from_bytes(amqp_message) return decoded_message diff --git a/azurefunctions-extensions-bindings-servicebus/tests/test_servicebus.py b/azurefunctions-extensions-bindings-servicebus/tests/test_servicebus.py index 51eb114..dee131c 100644 --- a/azurefunctions-extensions-bindings-servicebus/tests/test_servicebus.py +++ b/azurefunctions-extensions-bindings-servicebus/tests/test_servicebus.py @@ -149,3 +149,30 @@ def test_input_get_decoded_message_ex(self): _ = get_decoded_message("Invalid message") self.assertIn("Failed to decode ServiceBus content", e.exception.args[0]) + + def test_populated_properties(self): + sample_mbd = MockMBD( + version="1.0", + source="AzureServiceBusReceivedMessage", + content_type="application/octet-stream", + content=SERVICEBUS_SAMPLE_CONTENT + ) + + datum: Datum = Datum(value=sample_mbd, type="model_binding_data") + result: ServiceBusReceivedMessage = ServiceBusConverter.decode( + data=datum, trigger_metadata=None, pytype=ServiceBusReceivedMessage + ) + + self.assertIsNotNone(result) + self.assertIsInstance(result, ServiceBusSDK) + + self.assertIsNotNone(result.body) + self.assertIsNotNone(result.delivery_count) + self.assertIsNotNone(result.enqueued_time_utc) + self.assertIsNotNone(result.expires_at_utc) + self.assertIsNotNone(result.lock_token) + self.assertIsNotNone(result.locked_until_utc) + self.assertIsNotNone(result.message_id) + self.assertIsNotNone(result.sequence_number) + self.assertIsNotNone(result.state) + self.assertIsNotNone(result.time_to_live) From 07d87c34353a2b4bb6e8bf57f9848648f74b936a Mon Sep 17 00:00:00 2001 From: Victoria Hall Date: Mon, 27 Oct 2025 16:00:28 -0500 Subject: [PATCH 2/2] don't pass index --- .../azurefunctions/extensions/bindings/servicebus/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py b/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py index 52316e9..8dc8fba 100644 --- a/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py +++ b/azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/utils.py @@ -36,7 +36,7 @@ def get_lock_token(message: bytes, index: int) -> str: return lock_token_uuid -def get_amqp_message(message: bytes, index: int): +def get_amqp_message(message: bytes): """ Get the amqp message from the model_binding_data content and create the message. @@ -63,7 +63,7 @@ def get_decoded_message(content: bytes): lock_token = get_lock_token(content, index) delivery_anno_dict = {_X_OPT_LOCK_TOKEN: lock_token} - decoded_message = get_amqp_message(content, index) + decoded_message = get_amqp_message(content) decoded_message.delivery_annotations = delivery_anno_dict return decoded_message except Exception as e: