Skip to content

Commit cac6852

Browse files
authored
[ServiceBus] Fix typing in tracing method (#34324)
This fixes an issue when we try to set a readonly property. In use, this would yield a "can't set attribute" error. Move the cast down to not have it be an assignment to message.application_properties. Signed-off-by: Paul Van Eck <[email protected]>
1 parent e3c8657 commit cac6852

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Header(NamedTuple):
6262
This field contains the relative Message priority. Higher numbers indicate higher priority Messages.
6363
Messages with higher priorities MAY be delivered before those with lower priorities. An AMQP intermediary
6464
implementing distinct priority levels MUST do so in the following manner:
65-
65+
6666
- If n distince priorities are implemented and n is less than 10 - priorities 0 to (5 - ceiling(n/2))
6767
MUST be treated equivalently and MUST be the lowest effective priority. The priorities (4 + fioor(n/2))
6868
and above MUST be treated equivalently and MUST be the highest effective priority. The priorities
@@ -184,7 +184,7 @@ class Message(NamedTuple):
184184
delivery_annotations: Optional[Dict[Union[str, bytes], Any]] = None
185185
message_annotations: Optional[Dict[Union[str, bytes], Any]] = None
186186
properties: Optional[Properties] = None
187-
application_properties: Optional[Dict[Union[str, bytes], Any]] = None # TODO: make not read-only
187+
application_properties: Optional[Dict[Union[str, bytes], Any]] = None
188188
data: Optional[bytes] = None
189189
sequence: Optional[List[Any]] = None
190190
value: Optional[Any] = None

sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,7 @@ def update_message_app_properties(
361361
"""
362362
if not message.application_properties:
363363
message = message._replace(application_properties={})
364-
# TODO: fix error when typing pyamqp: `Property "application_properties" defined in "Message" is read-only `
365-
# may be able to add @property.setter to app props in pyamqp.Message to fix this
366-
message.application_properties = cast( # type: ignore[misc]
367-
Dict[Union[str, bytes], Any], message.application_properties
368-
)
369-
# casting from Optional to Dict above for use with setdefault
370-
message.application_properties.setdefault(key, value)
364+
cast(Dict[Union[str, bytes], Any], message.application_properties).setdefault(key, value)
371365
return message
372366

373367
@staticmethod

0 commit comments

Comments
 (0)