Skip to content

[Service Bus] Clarify application_properties returns bytes keys/values on receive#48078

Draft
EldertGrootenboer wants to merge 2 commits into
Azure:mainfrom
EldertGrootenboer:fix/servicebus-appproperties-bytes-docs-45082
Draft

[Service Bus] Clarify application_properties returns bytes keys/values on receive#48078
EldertGrootenboer wants to merge 2 commits into
Azure:mainfrom
EldertGrootenboer:fix/servicebus-appproperties-bytes-docs-45082

Conversation

@EldertGrootenboer

Copy link
Copy Markdown
Member

Summary

Fixes #45082.

Documentation-only change clarifying that when a message is received,
ServiceBusReceivedMessage.application_properties returns bytes keys and
bytes string values (for example {b"order_id": b"12345"}), not str.
String-key access such as props.get("order_id") returns None; callers must
use bytes keys and decode string values as needed.

This is intentional, long-standing behavior (the SDK's own tests assert bytes
keys), but the docstrings did not document it — the constructor :paramtype
even declared Dict[str, ...], which contradicts both the actual
Dict[Union[str, bytes], ...] parameter annotation and the receive behavior.

Changes

  • ServiceBusMessage constructor docstring — corrected
    :paramtype application_properties: from Dict[str, ...] to
    Dict[Union[str, bytes], ...] (matching the existing parameter annotation)
    and added a note about the received bytes behavior.
  • application_properties property — added a .. note:: explaining that,
    when a message is received, keys and string values are returned as bytes,
    with the recommended bytes-key access + decode pattern. Notes that the same
    applies to the raw AMQP annotations / delivery_annotations accessed via
    raw_amqp_message. Non-string values (int, bool, float, uuid.UUID,
    datetime) are returned as their native types.
  • README — added a sample showing how to read application properties from a
    received message.
  • CHANGELOG — added an "Other Changes" entry.

No behavioral/code change — the receive behavior is unchanged; only the
documentation.

Not in scope

Normalizing received keys/values to native strings (to match the .NET, Java, JS,
and Go SDKs) would be a breaking change on this GA package — it would break
every consumer relying on bytes keys today, including the SDK's own tests. That
is a separate design decision, not part of this documentation clarification.

…zure#45082)

- Correct the ServiceBusMessage constructor :paramtype for application_properties
  from Dict[str, ...] to Dict[Union[str, bytes], ...] to match the existing
  parameter annotation
- Add a note on the application_properties property that, when a message is
  received, keys and string values are returned as bytes, with the bytes-key
  access and decode pattern; note the same applies to the raw AMQP annotations
  and delivery_annotations accessed via raw_amqp_message
- Add a README sample for reading application properties from received messages
- Add a CHANGELOG Other Changes entry

Documentation-only change; no behavioral change.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
9 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Clarifies received Service Bus application-property byte behavior across public documentation.

Changes:

  • Corrects constructor and property documentation.
  • Adds a README usage example.
  • Records the clarification in the changelog.

Reviewed changes

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

File Description
README.md Documents bytes-key access and decoding.
CHANGELOG.md Records the documentation update.
_common/message.py Updates application-property docstrings and types.

Comment thread sdk/servicebus/azure-servicebus/README.md Outdated
Comment thread sdk/servicebus/azure-servicebus/README.md Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py Outdated
…5082)

- Guard the Optional application_properties against None before calling .get in
  both the docstring and README examples, so copying the sample does not raise
  AttributeError on a message that carries no application properties
- Correct the value-type note: an AMQP timestamp decodes to an integer
  (milliseconds), not a datetime; list only the verified native types
  (int, bool, float, uuid.UUID) and reframe as an AMQP-decode description

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 3 out of 3 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.

[azure-servicebus] Documentation unclear: application_properties uses bytes keys when receiving messages, not string keys

2 participants