6
6
# pylint:disable=specify-parameter-names-in-call
7
7
# pylint:disable=too-many-lines
8
8
import functools
9
+ from copy import deepcopy
9
10
from typing import TYPE_CHECKING , Any , Union , cast , Mapping
10
11
from xml .etree .ElementTree import ElementTree
11
12
72
73
)
73
74
from ...management ._xml_workaround_policy import ServiceBusXMLWorkaroundPolicy
74
75
from ...management ._handle_response_error import _handle_response_error
75
- from ...management ._model_workaround import avoid_timedelta_overflow
76
76
from ._utils import extract_data_template , extract_rule_data_template , get_next_template
77
77
from ...management ._utils import (
78
78
deserialize_rule_key_values ,
@@ -386,14 +386,14 @@ async def create_queue(self, queue_name: str, **kwargs) -> QueueProperties:
386
386
forward_dead_lettered_messages_to = forward_dead_lettered_messages_to ,
387
387
user_metadata = kwargs .pop ("user_metadata" , None ),
388
388
)
389
- to_create = queue ._to_internal_entity ()
389
+ to_create = queue ._to_internal_entity (self . fully_qualified_namespace )
390
390
create_entity_body = CreateQueueBody (
391
391
content = CreateQueueBodyContent (
392
392
queue_description = to_create , # type: ignore
393
393
)
394
394
)
395
395
request_body = create_entity_body .serialize (is_xml = True )
396
- await self ._create_forward_to_header_tokens (queue , kwargs )
396
+ await self ._create_forward_to_header_tokens (to_create , kwargs )
397
397
with _handle_response_error ():
398
398
entry_ele = cast (
399
399
ElementTree ,
@@ -419,39 +419,26 @@ async def update_queue(
419
419
Before calling this method, you should use `get_queue`, `create_queue` or `list_queues` to get a
420
420
`QueueProperties` instance, then update the properties. Only a portion of properties can
421
421
be updated. Refer to https://docs.microsoft.com/en-us/rest/api/servicebus/update-queue.
422
+ You could also pass keyword arguments for updating properties in the form of
423
+ `<property_name>=<property_value>` which will override whatever was specified in
424
+ the `QueueProperties` instance. Refer to ~azure.servicebus.management.QueueProperties for names of properties.
422
425
423
426
:param queue: The queue that is returned from `get_queue`, `create_queue` or `list_queues` and
424
427
has the updated properties.
425
428
:type queue: ~azure.servicebus.management.QueueProperties
426
429
:rtype: None
427
430
"""
428
-
429
- queue = create_properties_from_dict_if_needed (queue , QueueProperties )
430
- queue .forward_to = _normalize_entity_path_to_full_path_if_needed (
431
- queue .forward_to , self .fully_qualified_namespace
432
- )
433
- queue .forward_dead_lettered_messages_to = (
434
- _normalize_entity_path_to_full_path_if_needed (
435
- queue .forward_dead_lettered_messages_to ,
436
- self .fully_qualified_namespace ,
437
- )
438
- )
439
- to_update = queue ._to_internal_entity ()
440
-
441
- to_update .default_message_time_to_live = avoid_timedelta_overflow (
442
- to_update .default_message_time_to_live
443
- )
444
- to_update .auto_delete_on_idle = avoid_timedelta_overflow (
445
- to_update .auto_delete_on_idle
446
- )
431
+ # we should not mutate the input, making a copy first for update
432
+ queue = deepcopy (create_properties_from_dict_if_needed (queue , QueueProperties ))
433
+ to_update = queue ._to_internal_entity (self .fully_qualified_namespace , kwargs )
447
434
448
435
create_entity_body = CreateQueueBody (
449
436
content = CreateQueueBodyContent (
450
437
queue_description = to_update ,
451
438
)
452
439
)
453
440
request_body = create_entity_body .serialize (is_xml = True )
454
- await self ._create_forward_to_header_tokens (queue , kwargs )
441
+ await self ._create_forward_to_header_tokens (to_update , kwargs )
455
442
with _handle_response_error ():
456
443
await self ._impl .entity .put (
457
444
queue .name , # type: ignore
@@ -660,22 +647,18 @@ async def update_topic(
660
647
Before calling this method, you should use `get_topic`, `create_topic` or `list_topics` to get a
661
648
`TopicProperties` instance, then update the properties. Only a portion of properties can be updated.
662
649
Refer to https://docs.microsoft.com/en-us/rest/api/servicebus/update-topic.
650
+ You could also pass keyword arguments for updating properties in the form of
651
+ `<property_name>=<property_value>` which will override whatever was specified in
652
+ the `TopicProperties` instance. Refer to ~azure.servicebus.management.TopicProperties for names of properties.
663
653
664
654
:param topic: The topic that is returned from `get_topic`, `create_topic`, or `list_topics`
665
655
and has the updated properties.
666
656
:type topic: ~azure.servicebus.management.TopicProperties
667
657
:rtype: None
668
658
"""
669
659
670
- topic = create_properties_from_dict_if_needed (topic , TopicProperties )
671
- to_update = topic ._to_internal_entity ()
672
-
673
- to_update .default_message_time_to_live = avoid_timedelta_overflow ( # type: ignore
674
- to_update .default_message_time_to_live
675
- )
676
- to_update .auto_delete_on_idle = avoid_timedelta_overflow ( # type: ignore
677
- to_update .auto_delete_on_idle
678
- )
660
+ topic = deepcopy (create_properties_from_dict_if_needed (topic , TopicProperties ))
661
+ to_update = topic ._to_internal_entity (kwargs )
679
662
680
663
create_entity_body = CreateTopicBody (
681
664
content = CreateTopicBodyContent (
@@ -849,6 +832,7 @@ async def create_subscription(
849
832
:type auto_delete_on_idle: Union[~datetime.timedelta, str]
850
833
:rtype: ~azure.servicebus.management.SubscriptionProperties
851
834
"""
835
+ # pylint:disable=protected-access
852
836
_validate_entity_name_type (topic_name , display_name = "topic_name" )
853
837
forward_to = _normalize_entity_path_to_full_path_if_needed (
854
838
kwargs .pop ("forward_to" , None ), self .fully_qualified_namespace
@@ -882,15 +866,15 @@ async def create_subscription(
882
866
auto_delete_on_idle = kwargs .pop ("auto_delete_on_idle" , None ),
883
867
availability_status = None ,
884
868
)
885
- to_create = subscription ._to_internal_entity () # type: ignore # pylint:disable=protected-access
869
+ to_create = subscription ._to_internal_entity (self . fully_qualified_namespace ) # type: ignore
886
870
887
871
create_entity_body = CreateSubscriptionBody (
888
872
content = CreateSubscriptionBodyContent (
889
873
subscription_description = to_create , # type: ignore
890
874
)
891
875
)
892
876
request_body = create_entity_body .serialize (is_xml = True )
893
- await self ._create_forward_to_header_tokens (subscription , kwargs )
877
+ await self ._create_forward_to_header_tokens (to_create , kwargs )
894
878
with _handle_response_error ():
895
879
entry_ele = cast (
896
880
ElementTree ,
@@ -919,6 +903,10 @@ async def update_subscription(
919
903
920
904
Before calling this method, you should use `get_subscription`, `update_subscription` or `list_subscription`
921
905
to get a `SubscriptionProperties` instance, then update the properties.
906
+ You could also pass keyword arguments for updating properties in the form of
907
+ `<property_name>=<property_value>` which will override whatever was specified in
908
+ the `SubscriptionProperties` instance.
909
+ Refer to ~azure.servicebus.management.SubscriptionProperties for names of properties.
922
910
923
911
:param str topic_name: The topic that owns the subscription.
924
912
:param ~azure.servicebus.management.SubscriptionProperties subscription: The subscription that is returned
@@ -927,35 +915,17 @@ async def update_subscription(
927
915
"""
928
916
929
917
_validate_entity_name_type (topic_name , display_name = "topic_name" )
930
-
931
- subscription = create_properties_from_dict_if_needed (
932
- subscription , SubscriptionProperties
933
- )
934
- subscription .forward_to = _normalize_entity_path_to_full_path_if_needed (
935
- subscription .forward_to , self .fully_qualified_namespace
936
- )
937
- subscription .forward_dead_lettered_messages_to = (
938
- _normalize_entity_path_to_full_path_if_needed (
939
- subscription .forward_dead_lettered_messages_to ,
940
- self .fully_qualified_namespace ,
941
- )
942
- )
943
- to_update = subscription ._to_internal_entity ()
944
-
945
- to_update .default_message_time_to_live = avoid_timedelta_overflow ( # type: ignore
946
- to_update .default_message_time_to_live
947
- )
948
- to_update .auto_delete_on_idle = avoid_timedelta_overflow ( # type: ignore
949
- to_update .auto_delete_on_idle
950
- )
918
+ # we should not mutate the input, making a copy first for update
919
+ subscription = deepcopy (create_properties_from_dict_if_needed (subscription , SubscriptionProperties ))
920
+ to_update = subscription ._to_internal_entity (self .fully_qualified_namespace , kwargs )
951
921
952
922
create_entity_body = CreateSubscriptionBody (
953
923
content = CreateSubscriptionBodyContent (
954
924
subscription_description = to_update ,
955
925
)
956
926
)
957
927
request_body = create_entity_body .serialize (is_xml = True )
958
- await self ._create_forward_to_header_tokens (subscription , kwargs )
928
+ await self ._create_forward_to_header_tokens (to_update , kwargs )
959
929
with _handle_response_error ():
960
930
await self ._impl .subscription .put (
961
931
topic_name ,
@@ -1130,6 +1100,9 @@ async def update_rule(
1130
1100
1131
1101
Before calling this method, you should use `get_rule`, `create_rule` or `list_rules` to get a `RuleProperties`
1132
1102
instance, then update the properties.
1103
+ You could also pass keyword arguments for updating properties in the form of
1104
+ `<property_name>=<property_value>` which will override whatever was specified in
1105
+ the `RuleProperties` instance. Refer to ~azure.servicebus.management.RuleProperties for names of properties.
1133
1106
1134
1107
:param str topic_name: The topic that owns the subscription.
1135
1108
:param str subscription_name: The subscription that
@@ -1140,9 +1113,9 @@ async def update_rule(
1140
1113
:rtype: None
1141
1114
"""
1142
1115
_validate_topic_and_subscription_types (topic_name , subscription_name )
1143
-
1144
- rule = create_properties_from_dict_if_needed (rule , RuleProperties )
1145
- to_update = rule ._to_internal_entity ()
1116
+ # we should not mutate the input, making a copy first for update
1117
+ rule = deepcopy ( create_properties_from_dict_if_needed (rule , RuleProperties ) )
1118
+ to_update = rule ._to_internal_entity (kwargs )
1146
1119
1147
1120
create_entity_body = CreateRuleBody (
1148
1121
content = CreateRuleBodyContent (
0 commit comments