Skip to content

Commit 74a6797

Browse files
adamckaysimorenoh
andauthored
[Cosmos] Raise exception if invalid retry configuration specified for connection (Azure#23180)
* Raise exception if invalid retry configuration specified for connection * changelog and async client connection * Update CHANGELOG.md * added basic test case * Update CHANGELOG.md Co-authored-by: simorenoh <[email protected]> Co-authored-by: Simon Moreno <[email protected]>
1 parent fe08a0b commit 74a6797

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
This change will impact client application in terms of RUs and latency. Users relying on default `Session` consistency will need to pass it explicitly if their account consistency is different than `Session`.
1212
Please see [Consistency Levels in Azure Cosmos DB](https://docs.microsoft.com/azure/cosmos-db/consistency-levels) for more details.
1313
- Fixed invalid request body being sent when passing in `serverScript` body parameter to replace operations for trigger, sproc and udf resources.
14+
- Fixed TypeErrors not being thrown when passing in invalid connection retry policies to the client.
1415

1516
### 4.3.0b2 (2022-01-25)
1617

sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ def __init__(
164164
retry_backoff_factor=self.connection_policy.ConnectionRetryConfiguration.backoff_factor
165165
)
166166
else:
167-
TypeError("Unsupported retry policy. Must be an azure.cosmos.ConnectionRetryPolicy, int, or urllib3.Retry")
167+
raise TypeError(
168+
"Unsupported retry policy. Must be an azure.cosmos.ConnectionRetryPolicy, int, or urllib3.Retry")
168169

169170
proxies = kwargs.pop('proxies', {})
170171
if self.connection_policy.ProxyConfiguration and self.connection_policy.ProxyConfiguration.Host:

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ def __init__(
164164
retry_backoff_factor=self.connection_policy.ConnectionRetryConfiguration.backoff_factor
165165
)
166166
else:
167-
TypeError("Unsupported retry policy. Must be an azure.cosmos.ConnectionRetryPolicy, int, or urllib3.Retry")
167+
raise TypeError(
168+
"Unsupported retry policy. Must be an azure.cosmos.ConnectionRetryPolicy, int, or urllib3.Retry")
168169

169170
proxies = kwargs.pop('proxies', {})
170171
if self.connection_policy.ProxyConfiguration and self.connection_policy.ProxyConfiguration.Host:

sdk/cosmos/azure-cosmos/test/test_user_configs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
DATABASE_ID = "PythonSDKUserConfigTesters"
3737
CONTAINER_ID = "PythonSDKTestContainer"
3838

39+
3940
def get_test_item():
4041
item = {
4142
'id': 'Async_' + str(uuid.uuid4()),
@@ -44,9 +45,17 @@ def get_test_item():
4445
}
4546
return item
4647

48+
4749
@pytest.mark.usefixtures("teardown")
4850
class TestUserConfigs(unittest.TestCase):
4951

52+
def test_invalid_connection_retry_configuration(self):
53+
try:
54+
cosmos_client.CosmosClient(url=_test_config.host, credential=_test_config.masterKey,
55+
connection_retry_policy="Invalid Policy")
56+
except TypeError as e:
57+
self.assertTrue(str(e).startswith('Unsupported retry policy'))
58+
5059
def test_enable_endpoint_discovery(self):
5160
client_false = cosmos_client.CosmosClient(url=_test_config.host, credential=_test_config.masterKey,
5261
enable_endpoint_discovery=False)

0 commit comments

Comments
 (0)