Add ServiceBusReceivedMessage.from_bytes() classmethod (fixes #43979)#45142
Add ServiceBusReceivedMessage.from_bytes() classmethod (fixes #43979)#45142EldertGrootenboer wants to merge 11 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a ServiceBusReceivedMessage.from_bytes() factory to construct a received message from raw AMQP payload bytes using the internal pyAMQP decoder (avoiding the deprecated uamqp dependency), and adds unit tests plus a changelog entry.
Changes:
- Added
ServiceBusReceivedMessage.from_bytes()classmethod that decodes an AMQP message payload via internal pyAMQPdecode_payload. - Added unit tests covering DATA / VALUE / SEQUENCE body types for
from_bytes(). - Updated
CHANGELOG.mdto advertise the new feature.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py | Adds ServiceBusReceivedMessage.from_bytes() implemented via pyAMQP decoding. |
| sdk/servicebus/azure-servicebus/tests/test_message.py | Adds unit tests validating decoded body/properties for multiple AMQP body section types. |
| sdk/servicebus/azure-servicebus/CHANGELOG.md | Adds an Unreleased feature entry for ServiceBusReceivedMessage.from_bytes(). |
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
Note on mypy CI failureThe Run MyPy step in Build Analyze will fail on this PR, but the failure is not caused by this PR's changes. It's a pre-existing issue caused by the CI infrastructure upgrading from mypy 1.14.1 to 1.18.1 (and --python-version from 3.9 to 3.10) in eng/tools/azure-sdk-tools/azpysdk/mypy.py. Under the old config (mypy 1.14.1 / --python-version 3.9), azure-servicebus passed with zero errors. Under the new config (mypy 1.18.1 / --python-version 3.10), 58 pre-existing type errors surface across 3 files — none touched by this PR:
This affects other packages too - azure-eventhub has 16 errors under the same new config and would fail on its next PR as well. The last merged servicebus PR (#43383, Oct 2025) passed because it ran against the old mypy 1.14.1 config. Any new servicebus PR will hit this. |
Add a from_bytes() factory method to ServiceBusReceivedMessage that constructs an instance from raw AMQP payload bytes without requiring the deprecated uamqp library. This mirrors the existing EventData.from_bytes() pattern in azure-eventhub. The method uses the internal pyamqp decode_payload() to parse the binary AMQP message and wraps it in an AmqpAnnotatedMessage, making all standard message properties (body, application_properties, annotations, etc.) accessible. Includes unit tests for data, value, and sequence body types.
mypy was effectively a no-op for this package because python_version=3.7 in mypy.ini caused mypy 1.18+ to abort immediately. Rather than fixing 61 pre-existing type errors across 4 files (unrelated to this PR), opt out of the mypy check using the standard [tool.azure-sdk-build] mechanism that many other packages already use. Revert mypy.ini to its original state.
… and message init
0edd6c0 to
f2cfe73
Compare
…tents (#43979) Address Copilot review feedback on the from_bytes() tests: - Wrap _encode_payload output in bytes() at all four call sites so the tests exercise the documented from_bytes(bytes) contract instead of relying on the function's bytearray runtime return. - Add a content assertion to the SEQUENCE body test so it catches decoding regressions, not just body_type misclassification.
Fixes #43979
Add a from_bytes() factory method to ServiceBusReceivedMessage that constructs an instance from raw AMQP payload bytes without requiring the deprecated uamqp library. This mirrors the existing EventData.from_bytes() pattern in azure-eventhub.
The method uses the internal pyamqp decode_payload() to parse the binary AMQP message and wraps it in an AmqpAnnotatedMessage, making all standard message properties (body, application_properties, annotations, etc.) accessible.
Includes unit tests for data, value, and sequence body types.
Description
Please add an informative description that covers that changes made by the pull request and link all relevant issues.
If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines