Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServiceBus dict-representation acceptance and kwarg-update functionality #14807

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3f05de7
Merge pull request #1 from Azure/master
bradleydamato Oct 12, 2020
488ac14
Merge remote-tracking branch 'upstream/master'
bradleydamato Oct 12, 2020
0cc38d2
Merge branch 'master' of github.com:Azure/azure-sdk-for-python
bradleydamato Oct 18, 2020
4bde81c
Merge branch 'master' of github.com:Azure/azure-sdk-for-python
bradleydamato Oct 20, 2020
fe6fcdc
Adding kwarg update line to update_* functions
bradleydamato Oct 20, 2020
b65f309
ServiceBusAdministrationClient update_* methods now accept dictionary…
bradleydamato Oct 26, 2020
30d6948
ServiceBusSender methods now accept dict-representation
bradleydamato Oct 26, 2020
d6686f1
ServiceBusSender methods now accept list of dict-representations in s…
bradleydamato Oct 27, 2020
ea060e2
Message, Async ServiceBusSender, and Async ServiceBusAdministrationCl…
bradleydamato Oct 27, 2020
0f9fc56
Reverting change made to Message._from_list() method
bradleydamato Oct 27, 2020
34e41eb
Fixing indent size
bradleydamato Oct 27, 2020
ff63098
fixing Pylint errors
bradleydamato Oct 27, 2020
260b940
Fixing update_* kwarg update logic
bradleydamato Oct 28, 2020
881d13d
added util generic functions to take in dicts and create objects + ad…
swathipil Feb 18, 2021
9462f22
updated error messages for mgmt client
swathipil Feb 18, 2021
e394824
remove unnecessary kwarg check in update_topic
swathipil Feb 18, 2021
ac17178
remove error messages
swathipil Feb 18, 2021
a81445d
changed function name
swathipil Feb 18, 2021
cc0cdd4
Merge branch 'master' into ServiceBus_dict-representation_and_kwarg_u…
swathipil Feb 18, 2021
073670e
fix merge conflict, exceptions
swathipil Feb 18, 2021
2c1fe1e
fix test errors from merge conflict
swathipil Feb 19, 2021
0f7b1b4
Merge branch 'master' into ServiceBus_dict-representation_and_kwarg_u…
swathipil Feb 19, 2021
4d20f93
added test recordings
swathipil Feb 19, 2021
3f60783
fix mypy/pylint
swathipil Feb 19, 2021
c8e20a3
adams comments + update recordings
swathipil Feb 22, 2021
97d52b4
fix mypy/pylint
swathipil Feb 22, 2021
5b787d4
fix mypy error in message
swathipil Feb 22, 2021
eef0308
remove duplicate test
swathipil Feb 22, 2021
c8bfd20
adams comments
swathipil Feb 23, 2021
315b093
anna's comments
swathipil Mar 1, 2021
5e61e23
updated _from_list to check for Mapping, not dict
swathipil Mar 1, 2021
a23aecd
update changelog
swathipil Mar 2, 2021
49e25bb
Merge branch 'master' into ServiceBus_dict-representation_and_kwarg_u…
swathipil Mar 2, 2021
ee67888
change Mapping back to dict check
swathipil Mar 2, 2021
27f40bd
Update sdk/servicebus/azure-servicebus/CHANGELOG.md
swathipil Mar 2, 2021
a38c54f
bump minor version
swathipil Mar 2, 2021
f145073
Merge branch 'ServiceBus_dict-representation_and_kwarg_update' of htt…
swathipil Mar 2, 2021
803b142
_version update
swathipil Mar 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ def add(self, message):
:rtype: None
:raises: :class: ~azure.servicebus.exceptions.MessageContentTooLarge, when exceeding the size limit.
"""
if isinstance(message, dict):
temp_message = Message(message.pop('body'), **message)
swathipil marked this conversation as resolved.
Show resolved Hide resolved
message = temp_message
message = transform_messages_to_sendable_if_needed(message)
message_size = message.message.get_message_encoded_size()

Expand Down Expand Up @@ -588,6 +591,9 @@ class PeekedMessage(Message):

def __init__(self, message):
# type: (uamqp.message.Message) -> None
swathipil marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(message, dict):
temp_message = Message(message.pop('body'), **message)
message = temp_message
super(PeekedMessage, self).__init__(None, message=message) # type: ignore

def _to_outgoing_message(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ def schedule_messages(self, messages, schedule_time_utc, **kwargs):
"""
# pylint: disable=protected-access
self._open()
if isinstance(messages, list):
for index, each in enumerate(messages):
if isinstance(each, dict):
messages[index] = Message(each.pop("body"), **each)
else:
pass

if isinstance(messages, dict):
temp_messages = Message(messages.pop("body"), **messages)
messages = temp_messages

timeout = kwargs.pop("timeout", None)
if timeout is not None and timeout <= 0:
raise ValueError("The timeout must be greater than 0.")
Expand Down Expand Up @@ -316,6 +327,7 @@ def from_connection_string(
return cls(**constructor_args)

def send_messages(self, message, **kwargs):

# type: (Union[Message, BatchMessage, List[Message]], Any) -> None
"""Sends message and blocks until acknowledgement is received or operation times out.

Expand Down Expand Up @@ -346,6 +358,15 @@ def send_messages(self, message, **kwargs):
:caption: Send message.

"""
if isinstance(message, list):
swathipil marked this conversation as resolved.
Show resolved Hide resolved
for index, each in enumerate(message):
if isinstance(each, dict):
message[index] = Message(each.pop("body"), **each)
else:
pass
if isinstance(message, dict):
temporary_message = Message(message.pop('body'), **message)
message = temporary_message
timeout = kwargs.pop("timeout", None)
if timeout is not None and timeout <= 0:
raise ValueError("The timeout must be greater than 0.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ async def _open(self):
async def _send(self, message, timeout=None, last_exception=None):
await self._open()
default_timeout = self._handler._msg_timeout # pylint: disable=protected-access
if isinstance(message, dict):
temp_message = Message(message.pop("body"), **message)
message = temp_message
try:
self._set_msg_timeout(timeout, last_exception)
await self._handler.send_message_async(message.message)
Expand Down Expand Up @@ -165,6 +168,15 @@ async def schedule_messages(
"""
# pylint: disable=protected-access
await self._open()
if isinstance(messages, list):
for index, each in messages:
if isinstance(each, dict):
messages[index] = Message(each.pop("body"), **each)
else:
pass
if isinstance(messages, dict):
temp_message = Message(messages.pop("body"), **messages)
messages = temp_message
timeout = kwargs.pop("timeout", None)
if timeout is not None and timeout <= 0:
raise ValueError("The timeout must be greater than 0.")
Expand Down Expand Up @@ -286,6 +298,15 @@ async def send_messages(self, message: Union[Message, BatchMessage, List[Message
:caption: Send message.

"""
if isinstance(message, list):
for index, each in message:
if isinstance(each, dict):
message[index] = Message(each.pop("body"), **each)
else:
pass
if isinstance(message, dict):
temp_message = Message(message.pop("body"), **message)
message = temp_message
timeout = kwargs.pop("timeout", None)
if timeout is not None and timeout <= 0:
raise ValueError("The timeout must be greater than 0.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,12 @@ async def update_queue(self, queue: QueueProperties, **kwargs) -> None:
:type queue: ~azure.servicebus.management.QueueProperties
:rtype: None
"""
if isinstance(queue, dict):
dict_to_queue_props = QueueProperties(queue.pop("name"), **queue)
to_update = dict_to_queue_props._to_internal_entity()
else:
to_update = queue._to_internal_entity()

to_update = queue._to_internal_entity()
to_update.default_message_time_to_live = avoid_timedelta_overflow(to_update.default_message_time_to_live)
to_update.auto_delete_on_idle = avoid_timedelta_overflow(to_update.auto_delete_on_idle)

Expand Down Expand Up @@ -479,8 +483,11 @@ async def update_topic(self, topic: TopicProperties, **kwargs) -> None:
:type topic: ~azure.servicebus.management.TopicProperties
:rtype: None
"""

to_update = topic._to_internal_entity()
if isinstance(topic, dict):
dict_to_topic_props = TopicProperties(topic.pop("name"), **topic)
to_update = dict_to_topic_props._to_internal_entity()
else:
to_update = topic._to_internal_entity()

to_update.default_message_time_to_live = avoid_timedelta_overflow(to_update.default_message_time_to_live)
to_update.auto_delete_on_idle = avoid_timedelta_overflow(to_update.auto_delete_on_idle)
Expand Down Expand Up @@ -685,8 +692,11 @@ async def update_subscription(
:rtype: None
"""
_validate_entity_name_type(topic_name, display_name='topic_name')

to_update = subscription._to_internal_entity()
if isinstance(subscription, dict):
dict_to_subscription_props = SubscriptionProperties(subscription.pop("name"), **subscription)
to_update = dict_to_subscription_props._to_internal_entity()
else:
to_update = subscription._to_internal_entity()

to_update.default_message_time_to_live = avoid_timedelta_overflow(to_update.default_message_time_to_live)
to_update.auto_delete_on_idle = avoid_timedelta_overflow(to_update.auto_delete_on_idle)
Expand Down Expand Up @@ -853,8 +863,11 @@ async def update_rule(
:rtype: None
"""
_validate_topic_and_subscription_types(topic_name, subscription_name)

to_update = rule._to_internal_entity()
if isinstance(rule, dict):
dict_to_rule_props = RuleProperties(rule.pop('name'), **rule)
to_update = dict_to_rule_props._to_internal_entity()
else:
to_update = rule._to_internal_entity()

create_entity_body = CreateRuleBody(
content=CreateRuleBodyContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,15 @@ def update_queue(self, queue, **kwargs):
:type queue: ~azure.servicebus.management.QueueProperties
:rtype: None
"""

to_update = queue._to_internal_entity()

if kwargs:
queue._internal_qd = None
queue.__dict__.update([(key, kwargs.pop(key)) for key in kwargs.copy() if key in queue.__dict__.keys()])

if isinstance(queue, dict):
dict_to_queue_props = QueueProperties(queue.pop('name'), **queue)
to_update = dict_to_queue_props._to_internal_entity()
else:
to_update = queue._to_internal_entity()
to_update.default_message_time_to_live = avoid_timedelta_overflow(to_update.default_message_time_to_live)
to_update.auto_delete_on_idle = avoid_timedelta_overflow(to_update.auto_delete_on_idle)

Expand Down Expand Up @@ -482,9 +488,15 @@ def update_topic(self, topic, **kwargs):
:type topic: ~azure.servicebus.management.TopicProperties
:rtype: None
"""

to_update = topic._to_internal_entity()

if kwargs:
topic._internal_qd = None
topic.__dict__.update([(key, kwargs.pop(key)) for key in kwargs.copy() if key in topic.__dict__.keys()])

if isinstance(topic, dict):
dict_to_topic_props = TopicProperties(topic.pop('name'), **topic)
to_update = dict_to_topic_props._to_internal_entity()
else:
to_update = topic._to_internal_entity()
to_update.default_message_time_to_live = kwargs.get(
"default_message_time_to_live") or topic.default_message_time_to_live
to_update.duplicate_detection_history_time_window = kwargs.get(
Expand Down Expand Up @@ -692,8 +704,15 @@ def update_subscription(self, topic_name, subscription, **kwargs):
:rtype: None
"""
_validate_entity_name_type(topic_name, display_name='topic_name')

to_update = subscription._to_internal_entity()

if kwargs:
subscription._internal_qd = None
subscription.__dict__.update([(key, kwargs.pop(key)) for key in kwargs.copy() if key in subscription.__dict__.keys()])
if isinstance(subscription, dict):
dict_to_subscription_props = SubscriptionProperties(subscription.pop('name'), **subscription)
to_update = dict_to_subscription_props._to_internal_entity()
else:
to_update = subscription._to_internal_entity()

to_update.default_message_time_to_live = avoid_timedelta_overflow(to_update.default_message_time_to_live)
to_update.auto_delete_on_idle = avoid_timedelta_overflow(to_update.auto_delete_on_idle)
Expand Down Expand Up @@ -856,8 +875,15 @@ def update_rule(self, topic_name, subscription_name, rule, **kwargs):
:rtype: None
"""
_validate_topic_and_subscription_types(topic_name, subscription_name)
if kwargs:
rule._internal_qd = None
rule.__dict__.update([(key, kwargs.pop(key)) for key in kwargs.copy() if key in rule.__dict__.keys()])
if isinstance(rule, dict):
dict_to_rule_props = RuleProperties(rule.pop("name"), **rule)
to_update = dict_to_rule_props._to_internal_entity()
else:
to_update = rule._to_internal_entity()

to_update = rule._to_internal_entity()

create_entity_body = CreateRuleBody(
content=CreateRuleBodyContent(
Expand Down