Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
8 changes: 7 additions & 1 deletion sdk/servicebus/azure-servicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Release History

## 7.1.2 (Unreleased)
## 7.2.0 (Unreleased)

**New Features**

* `ServiceBusAdministrationClient.update_*` methods now accept keyword arguments to override the properties specified in the model instance.

**Bug Fixes**

* Fixed a bug that `update_queue` and `update_subscription` mutating the properties `forward_to` and `forward_dead_lettered_messages_to` of the model instance when those properties are entities instead of full paths.

## 7.1.1 (2021-04-07)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Licensed under the MIT License.
# ------------------------------------

VERSION = "7.1.2"
VERSION = "7.2.0"
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# pylint:disable=specify-parameter-names-in-call
# pylint:disable=too-many-lines
import functools
from copy import deepcopy
from typing import TYPE_CHECKING, Any, Union, cast, Mapping
from xml.etree.ElementTree import ElementTree

Expand Down Expand Up @@ -78,6 +79,7 @@
deserialize_rule_key_values,
serialize_rule_key_values,
create_properties_from_dict_if_needed,
override_properties_with_keyword_arguments,
_normalize_entity_path_to_full_path_if_needed,
_validate_entity_name_type,
_validate_topic_and_subscription_types,
Expand Down Expand Up @@ -425,8 +427,8 @@ async def update_queue(
:type queue: ~azure.servicebus.management.QueueProperties
:rtype: None
"""

queue = create_properties_from_dict_if_needed(queue, QueueProperties)
# we should not mutate the input, making a copy first for update
queue = deepcopy(create_properties_from_dict_if_needed(queue, QueueProperties))
queue.forward_to = _normalize_entity_path_to_full_path_if_needed(
queue.forward_to, self.fully_qualified_namespace
)
Expand All @@ -436,6 +438,10 @@ async def update_queue(
self.fully_qualified_namespace,
)
)

property_keyword_arguments = {key: kwargs.pop(key) for key in set(kwargs.keys()) if key in queue.keys()}
override_properties_with_keyword_arguments(queue, **property_keyword_arguments)

to_update = queue._to_internal_entity()

to_update.default_message_time_to_live = avoid_timedelta_overflow(
Expand Down Expand Up @@ -667,7 +673,9 @@ async def update_topic(
:rtype: None
"""

topic = create_properties_from_dict_if_needed(topic, TopicProperties)
topic = deepcopy(create_properties_from_dict_if_needed(topic, TopicProperties))
property_keyword_arguments = {key: kwargs.pop(key) for key in set(kwargs.keys()) if key in topic.keys()}
override_properties_with_keyword_arguments(topic, **property_keyword_arguments)
to_update = topic._to_internal_entity()

to_update.default_message_time_to_live = avoid_timedelta_overflow( # type: ignore
Expand Down Expand Up @@ -927,10 +935,8 @@ async def update_subscription(
"""

_validate_entity_name_type(topic_name, display_name="topic_name")

subscription = create_properties_from_dict_if_needed(
subscription, SubscriptionProperties
)
# we should not mutate the input, making a copy first for update
subscription = deepcopy(create_properties_from_dict_if_needed(subscription, SubscriptionProperties))
subscription.forward_to = _normalize_entity_path_to_full_path_if_needed(
subscription.forward_to, self.fully_qualified_namespace
)
Expand All @@ -940,6 +946,9 @@ async def update_subscription(
self.fully_qualified_namespace,
)
)
property_keyword_arguments = {key: kwargs.pop(key) for key in set(kwargs.keys()) if key in subscription.keys()}
override_properties_with_keyword_arguments(subscription, **property_keyword_arguments)

to_update = subscription._to_internal_entity()

to_update.default_message_time_to_live = avoid_timedelta_overflow( # type: ignore
Expand Down Expand Up @@ -1140,8 +1149,10 @@ async def update_rule(
:rtype: None
"""
_validate_topic_and_subscription_types(topic_name, subscription_name)

rule = create_properties_from_dict_if_needed(rule, RuleProperties)
# we should not mutate the input, making a copy first for update
rule = deepcopy(create_properties_from_dict_if_needed(rule, RuleProperties))
property_keyword_arguments = {key: kwargs.pop(key) for key in set(kwargs.keys()) if key in rule.keys()}
override_properties_with_keyword_arguments(rule, **property_keyword_arguments)
to_update = rule._to_internal_entity()

create_entity_body = CreateRuleBody(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# pylint:disable=specify-parameter-names-in-call
# pylint:disable=too-many-lines
import functools
from copy import deepcopy
from typing import TYPE_CHECKING, Dict, Any, Union, cast, Mapping
from xml.etree.ElementTree import ElementTree

Expand Down Expand Up @@ -47,6 +48,7 @@
serialize_rule_key_values,
extract_rule_data_template,
create_properties_from_dict_if_needed,
override_properties_with_keyword_arguments,
_normalize_entity_path_to_full_path_if_needed,
_validate_entity_name_type,
_validate_topic_and_subscription_types,
Expand Down Expand Up @@ -416,7 +418,8 @@ def update_queue(self, queue, **kwargs):
:type queue: ~azure.servicebus.management.QueueProperties
:rtype: None
"""
queue = create_properties_from_dict_if_needed(queue, QueueProperties)
# we should not mutate the input, making a copy first for update
queue = deepcopy(create_properties_from_dict_if_needed(queue, QueueProperties))
queue.forward_to = _normalize_entity_path_to_full_path_if_needed(
queue.forward_to, self.fully_qualified_namespace
)
Expand All @@ -426,8 +429,11 @@ def update_queue(self, queue, **kwargs):
self.fully_qualified_namespace,
)
)
to_update = queue._to_internal_entity()

property_keyword_arguments = {key: kwargs.pop(key) for key in set(kwargs.keys()) if key in queue.keys()}
override_properties_with_keyword_arguments(queue, **property_keyword_arguments)

to_update = queue._to_internal_entity()
to_update.default_message_time_to_live = avoid_timedelta_overflow(
to_update.default_message_time_to_live
)
Expand Down Expand Up @@ -656,19 +662,12 @@ def update_topic(self, topic, **kwargs):
:type topic: ~azure.servicebus.management.TopicProperties
:rtype: None
"""

topic = create_properties_from_dict_if_needed(topic, TopicProperties)
# we should not mutate the input, making a copy first for update
topic = deepcopy(create_properties_from_dict_if_needed(topic, TopicProperties))
property_keyword_arguments = {key: kwargs.pop(key) for key in set(kwargs.keys()) if key in topic.keys()}
override_properties_with_keyword_arguments(topic, **property_keyword_arguments)
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("duplicate_detection_history_time_window")
or topic.duplicate_detection_history_time_window
)

to_update.default_message_time_to_live = avoid_timedelta_overflow( # type: ignore
to_update.default_message_time_to_live
)
Expand Down Expand Up @@ -920,9 +919,11 @@ def update_subscription(self, topic_name, subscription, **kwargs):
from `get_subscription`, `update_subscription` or `list_subscription` and has the updated properties.
:rtype: None
"""

_validate_entity_name_type(topic_name, display_name="topic_name")
subscription = create_properties_from_dict_if_needed(subscription, SubscriptionProperties) # type: ignore
# we should not mutate the input, making a copy first for update
subscription = deepcopy(
create_properties_from_dict_if_needed(subscription, SubscriptionProperties) # type: ignore
)
subscription.forward_to = _normalize_entity_path_to_full_path_if_needed(
subscription.forward_to, self.fully_qualified_namespace
)
Expand All @@ -932,6 +933,9 @@ def update_subscription(self, topic_name, subscription, **kwargs):
self.fully_qualified_namespace,
)
)
property_keyword_arguments = {key: kwargs.pop(key) for key in set(kwargs.keys()) if key in subscription.keys()}
override_properties_with_keyword_arguments(subscription, **property_keyword_arguments)

to_update = subscription._to_internal_entity()

to_update.default_message_time_to_live = avoid_timedelta_overflow( # type: ignore
Expand Down Expand Up @@ -1121,8 +1125,10 @@ def update_rule(self, topic_name, subscription_name, rule, **kwargs):
:rtype: None
"""
_validate_topic_and_subscription_types(topic_name, subscription_name)

rule = create_properties_from_dict_if_needed(rule, RuleProperties)
# we should not mutate the input, making a copy first for update
rule = deepcopy(create_properties_from_dict_if_needed(rule, RuleProperties))
property_keyword_arguments = {key: kwargs.pop(key) for key in set(kwargs.keys()) if key in rule.keys()}
override_properties_with_keyword_arguments(rule, **property_keyword_arguments)
to_update = rule._to_internal_entity()

create_entity_body = CreateRuleBody(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,12 @@ def create_properties_from_dict_if_needed(properties, sb_resource_type):
sb_resource_type.__name__
)
)


def override_properties_with_keyword_arguments(properties, **kwargs):
# type: (PropertiesType, Any) -> None
if not kwargs:
return
for key, _ in kwargs:
if key in properties:
properties[key] = kwargs.get(key)
Loading