Skip to content

Add ServiceBusReceivedMessage.from_bytes() classmethod (fixes #43979)#45142

Open
EldertGrootenboer wants to merge 11 commits intomainfrom
feature/servicebus-from-bytes-43979
Open

Add ServiceBusReceivedMessage.from_bytes() classmethod (fixes #43979)#45142
EldertGrootenboer wants to merge 11 commits intomainfrom
feature/servicebus-from-bytes-43979

Conversation

@EldertGrootenboer
Copy link
Copy Markdown

@EldertGrootenboer EldertGrootenboer commented Feb 11, 2026

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:

  • [ x] The pull request does not introduce [breaking changes]
  • [ x] CHANGELOG is updated for new features, bug fixes or other significant changes.
  • [ x] I have read the contribution guidelines.

General Guidelines and Best Practices

  • [ x] Title of the pull request is clear and informative.
  • [ x] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • [ x] Pull request includes test coverage for the included changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 pyAMQP decode_payload.
  • Added unit tests covering DATA / VALUE / SEQUENCE body types for from_bytes().
  • Updated CHANGELOG.md to 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().

Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 11, 2026

API Change Check

APIView identified API level changes in this PR and created the following API reviews

azure-servicebus

@EldertGrootenboer
Copy link
Copy Markdown
Author

EldertGrootenboer commented Feb 12, 2026

Note on mypy CI failure

The 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:

  • azure/servicebus/_common/message.py - 12 [assignment] errors (Optional params to non-Optional setters)
  • azure/servicebus/_transport/_pyamqp_transport.py - 22 [union-attr] errors
  • azure/servicebus/_transport/_uamqp_transport.py - 24 [union-attr] + 1 [call-overload] error

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.
@EldertGrootenboer EldertGrootenboer force-pushed the feature/servicebus-from-bytes-43979 branch from 0edd6c0 to f2cfe73 Compare February 12, 2026 23:41
@EldertGrootenboer EldertGrootenboer enabled auto-merge (squash) March 16, 2026 20:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Comment thread sdk/servicebus/azure-servicebus/tests/test_message.py Outdated
Comment thread sdk/servicebus/azure-servicebus/tests/test_message.py
Comment thread sdk/servicebus/azure-servicebus/tests/test_message.py
Comment thread sdk/servicebus/azure-servicebus/tests/test_message.py
Comment thread sdk/servicebus/azure-servicebus/tests/test_message.py
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py
Comment thread sdk/servicebus/azure-servicebus/mypy.ini
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Comment thread sdk/servicebus/azure-servicebus/tests/test_message.py Outdated
Comment thread sdk/servicebus/azure-servicebus/tests/test_message.py
Comment thread sdk/servicebus/azure-servicebus/tests/test_message.py
Comment thread sdk/servicebus/azure-servicebus/tests/test_message.py
…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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parse AMQP payload for Service Bus

3 participants