|
1 | 1 | """
|
2 | 2 | Lowest level connection
|
3 | 3 | """
|
| 4 | +import sys |
4 | 5 | import logging
|
5 | 6 | import uuid
|
6 | 7 | from threading import local
|
7 |
| -from typing import Any, Dict, List, Mapping, Optional, Sequence, cast |
| 8 | +from typing import Any, Dict, List, Mapping, Optional, Sequence, Union, cast |
| 9 | +if sys.version_info >= (3, 8): |
| 10 | + from typing import Literal |
| 11 | +else: |
| 12 | + from typing_extensions import Literal |
8 | 13 |
|
| 14 | +from botocore.config import _RetryDict |
9 | 15 | import botocore.client
|
10 | 16 | import botocore.exceptions
|
11 | 17 | from botocore.client import ClientError
|
@@ -247,6 +253,7 @@ def __init__(self,
|
247 | 253 | read_timeout_seconds: Optional[float] = None,
|
248 | 254 | connect_timeout_seconds: Optional[float] = None,
|
249 | 255 | max_retry_attempts: Optional[int] = None,
|
| 256 | + retry_configuration: Optional[Union[Literal["LEGACY"], "_RetryDict"]] = None, |
250 | 257 | max_pool_connections: Optional[int] = None,
|
251 | 258 | extra_headers: Optional[Mapping[str, str]] = None,
|
252 | 259 | aws_access_key_id: Optional[str] = None,
|
@@ -277,6 +284,11 @@ def __init__(self,
|
277 | 284 | else:
|
278 | 285 | self._max_retry_attempts_exception = get_settings_value('max_retry_attempts')
|
279 | 286 |
|
| 287 | + if retry_configuration is not None: |
| 288 | + self._retry_configuration = retry_configuration |
| 289 | + else: |
| 290 | + self._retry_configuration = get_settings_value('retry_configuration') |
| 291 | + |
280 | 292 | if max_pool_connections is not None:
|
281 | 293 | self._max_pool_connections = max_pool_connections
|
282 | 294 | else:
|
@@ -399,15 +411,22 @@ def client(self) -> BotocoreBaseClientPrivate:
|
399 | 411 | # if the client does not have credentials, we create a new client
|
400 | 412 | # otherwise the client is permanently poisoned in the case of metadata service flakiness when using IAM roles
|
401 | 413 | if not self._client or (self._client._request_signer and not self._client._request_signer._credentials):
|
| 414 | + # Check if we are using the "LEGACY" retry mode to keep previous PynamoDB |
| 415 | + # retry behavior, or if we are using the new retry configuration settings. |
| 416 | + if self._retry_configuration != "LEGACY": |
| 417 | + retries = self._retry_configuration |
| 418 | + else: |
| 419 | + retries = { |
| 420 | + 'total_max_attempts': 1 + self._max_retry_attempts_exception, |
| 421 | + 'mode': 'standard', |
| 422 | + } |
| 423 | + |
402 | 424 | config = botocore.client.Config(
|
403 | 425 | parameter_validation=False, # Disable unnecessary validation for performance
|
404 | 426 | connect_timeout=self._connect_timeout_seconds,
|
405 | 427 | read_timeout=self._read_timeout_seconds,
|
406 | 428 | max_pool_connections=self._max_pool_connections,
|
407 |
| - retries={ |
408 |
| - 'total_max_attempts': 1 + self._max_retry_attempts_exception, |
409 |
| - 'mode': 'standard', |
410 |
| - } |
| 429 | + retries=retries |
411 | 430 | )
|
412 | 431 | self._client = cast(BotocoreBaseClientPrivate, self.session.create_client(SERVICE_NAME, self.region, endpoint_url=self.host, config=config))
|
413 | 432 |
|
|
0 commit comments