Skip to content

Commit 6364ba3

Browse files
authored
Honor MWR config in client (Azure#40999)
* fix mwr bug * fix texts and add changelog
1 parent 1ae42ae commit 6364ba3

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Breaking Changes
88

99
#### Bugs Fixed
10+
* Fixed bug where `multiple_write_locations` option in client was not being honored. See [PR 40999](https://github.com/Azure/azure-sdk-for-python/pull/40999).
1011

1112
#### Other Changes
1213

sdk/cosmos/azure-cosmos/azure/cosmos/_global_endpoint_manager.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ def __init__(self, client):
5858
self.last_refresh_time = 0
5959
self._database_account_cache = None
6060

61-
def get_use_multiple_write_locations(self):
62-
return self.location_cache.can_use_multiple_write_locations()
63-
6461
def get_refresh_time_interval_in_ms_stub(self):
6562
return constants._Constants.DefaultEndpointsRefreshTime
6663

sdk/cosmos/azure-cosmos/azure/cosmos/_service_request_retry_policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def ShouldRetry(self):
5858

5959
self.request.last_routed_location_endpoint_within_region = self.request.location_endpoint_to_route
6060
if (_OperationType.IsReadOnlyOperation(self.request.operation_type)
61-
or self.global_endpoint_manager.get_use_multiple_write_locations()):
61+
or self.global_endpoint_manager.can_use_multiple_write_locations(self.request)):
6262
self.update_location_cache()
6363
# We just directly got to the next location in case of read requests
6464
# We don't retry again on the same region for regional endpoint

sdk/cosmos/azure-cosmos/azure/cosmos/aio/_global_endpoint_manager_async.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ def __init__(self, client):
6262
self.last_refresh_time = 0
6363
self._database_account_cache = None
6464

65-
def get_use_multiple_write_locations(self):
66-
return self.location_cache.can_use_multiple_write_locations()
67-
6865
def get_refresh_time_interval_in_ms_stub(self):
6966
return constants._Constants.DefaultEndpointsRefreshTime
7067

sdk/cosmos/azure-cosmos/tests/test_fault_injection_transport.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ def test_mwr_succeeds(self: "TestFaultInjectionTransport"):
297297

298298
initialized_objects = self.setup_method_with_custom_transport(
299299
custom_transport,
300-
preferred_locations=["First Region", "Second Region"])
300+
preferred_locations=["First Region", "Second Region"],
301+
multiple_write_locations=True
302+
)
301303
container: ContainerProxy = initialized_objects["col"]
302304

303305
created_document = container.create_item(body=document_definition)
@@ -347,7 +349,9 @@ def test_mwr_region_down_succeeds(self: "TestFaultInjectionTransport"):
347349

348350
initialized_objects = self.setup_method_with_custom_transport(
349351
custom_transport,
350-
preferred_locations=["First Region", "Second Region"])
352+
preferred_locations=["First Region", "Second Region"],
353+
multiple_write_locations=True
354+
)
351355
container: ContainerProxy = initialized_objects["col"]
352356

353357
start:float = time.perf_counter()
@@ -466,7 +470,9 @@ def test_mwr_all_regions_down(self: "TestFaultInjectionTransport"):
466470

467471
initialized_objects = self.setup_method_with_custom_transport(
468472
custom_transport,
469-
preferred_locations=["First Region", "Second Region"])
473+
preferred_locations=["First Region", "Second Region"],
474+
multiple_write_locations=True
475+
)
470476
container: ContainerProxy = initialized_objects["col"]
471477
with pytest.raises(ServiceRequestError):
472478
container.upsert_item(body=document_definition)

sdk/cosmos/azure-cosmos/tests/test_fault_injection_transport_async.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ async def test_mwr_succeeds_async(self: "TestFaultInjectionTransportAsync"):
330330

331331
initialized_objects = await TestFaultInjectionTransportAsync.setup_method_with_custom_transport(
332332
custom_transport,
333-
preferred_locations=["First Region", "Second Region"])
333+
preferred_locations=["First Region", "Second Region"],
334+
multiple_write_locations=True
335+
)
334336
try:
335337
container: ContainerProxy = initialized_objects["col"]
336338

@@ -383,7 +385,9 @@ async def test_mwr_region_down_succeeds_async(self: "TestFaultInjectionTransport
383385

384386
initialized_objects = await TestFaultInjectionTransportAsync.setup_method_with_custom_transport(
385387
custom_transport,
386-
preferred_locations=["First Region", "Second Region"])
388+
preferred_locations=["First Region", "Second Region"],
389+
multiple_write_locations=True
390+
)
387391
try:
388392
container: ContainerProxy = initialized_objects["col"]
389393

@@ -508,7 +512,9 @@ async def test_mwr_all_regions_down_async(self: "TestFaultInjectionTransportAsyn
508512

509513
initialized_objects = await TestFaultInjectionTransportAsync.setup_method_with_custom_transport(
510514
custom_transport,
511-
preferred_locations=["First Region", "Second Region"])
515+
preferred_locations=["First Region", "Second Region"],
516+
multiple_write_locations=True
517+
)
512518
try:
513519
container: ContainerProxy = initialized_objects["col"]
514520
with pytest.raises(ServiceRequestError):

0 commit comments

Comments
 (0)