diff --git a/.changes/1.43.127.json b/.changes/1.43.127.json
new file mode 100644
index 000000000..b95039cfe
--- /dev/null
+++ b/.changes/1.43.127.json
@@ -0,0 +1,12 @@
+[
+ {
+ "category": "``athena``",
+ "description": "Update athena client to latest version",
+ "type": "api-change"
+ },
+ {
+ "category": "Retries",
+ "description": "Fixed a KeyError raised by the handler that adds the amz-sdk-invocation-id header when a request-created handler ran on a request that was not sent through the endpoint, such as a request built directly in a test.",
+ "type": "bugfix"
+ }
+]
\ No newline at end of file
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 7e8b7f3dd..bc6dbcb87 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -2,6 +2,13 @@
CHANGELOG
=========
+1.43.127
+========
+
+* api-change:``athena``: Update athena client to latest version
+* bugfix:Retries: Fixed a KeyError raised by the handler that adds the amz-sdk-invocation-id header when a request-created handler ran on a request that was not sent through the endpoint, such as a request built directly in a test.
+
+
1.43.126
========
diff --git a/botocore/__init__.py b/botocore/__init__.py
index 3e4785243..f68433892 100644
--- a/botocore/__init__.py
+++ b/botocore/__init__.py
@@ -17,7 +17,7 @@ import os
import re
from logging import NullHandler
-__version__ = '1.43.126'
+__version__ = '1.43.127'
# Configure default logger to do nothing
diff --git a/botocore/data/athena/2017-05-18/service-2.json b/botocore/data/athena/2017-05-18/service-2.json
index 0c20aba33..214a381f6 100644
--- a/botocore/data/athena/2017-05-18/service-2.json
+++ b/botocore/data/athena/2017-05-18/service-2.json
@@ -4,8 +4,11 @@
"apiVersion":"2017-05-18",
"endpointPrefix":"athena",
"jsonVersion":"1.1",
- "protocol":"json",
- "protocols":["json"],
+ "protocol":"smithy-rpc-v2-cbor",
+ "protocols":[
+ "smithy-rpc-v2-cbor",
+ "json"
+ ],
"serviceFullName":"Amazon Athena",
"serviceId":"Athena",
"signatureVersion":"v4",
diff --git a/botocore/retries/standard.py b/botocore/retries/standard.py
index 996460523..e6d84a6dd 100644
--- a/botocore/retries/standard.py
+++ b/botocore/retries/standard.py
@@ -130,7 +130,14 @@ class MaxAttemptsSeeder:
self._max_attempts = max_attempts
def seed_max_attempts(self, request, **kwargs):
- retries_context = request.context.setdefault('retries', {})
+ # The endpoint creates the retries context, with the invocation id,
+ # before it emits ``request-created``. A request that has no context
+ # did not come from the endpoint (for example one a test built and
+ # emitted itself), so leave it alone rather than create a partial
+ # context that ``add_retry_headers`` cannot complete.
+ retries_context = request.context.get('retries')
+ if retries_context is None:
+ return
retries_context['max'] = self._max_attempts
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 177485ca1..6d762fe64 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -59,7 +59,7 @@ copyright = f'{current_year}, Amazon Web Services, Inc'
# The short X.Y version.
version = '1.43.1'
# The full version, including alpha/beta/rc tags.
-release = '1.43.126'
+release = '1.43.127'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/tests/unit/retries/test_standard_retry_v2_1.py b/tests/unit/retries/test_standard_retry_v2_1.py
index d65189a15..66a4b423c 100644
--- a/tests/unit/retries/test_standard_retry_v2_1.py
+++ b/tests/unit/retries/test_standard_retry_v2_1.py
@@ -491,7 +491,17 @@ class TestMaxAttemptsInRequestHeader(BaseRetryTest):
headers = self._sdk_request_headers(config, [200])
self.assertEqual(headers, [b'attempt=1; max=4'])
- def test_seeder_adds_max_to_empty_context(self):
+ def test_seeder_adds_max_to_existing_context(self):
request = AWSRequest()
+ request.context['retries'] = {'invocation-id': 'abc-123'}
standard.MaxAttemptsSeeder(3).seed_max_attempts(request)
- self.assertEqual(request.context['retries'], {'max': 3})
+ self.assertEqual(
+ request.context['retries'], {'invocation-id': 'abc-123', 'max': 3}
+ )
+
+ def test_seeder_skips_request_without_retries_context(self):
+ # The endpoint creates the context before ``request-created``; a
+ # request without one did not come from the endpoint.
+ request = AWSRequest()
+ standard.MaxAttemptsSeeder(3).seed_max_attempts(request)
+ self.assertNotIn('retries', request.context)
diff --git a/tests/unit/test_handlers.py b/tests/unit/test_handlers.py
index afe84dc85..d459ad3a8 100644
--- a/tests/unit/test_handlers.py
+++ b/tests/unit/test_handlers.py
@@ -765,6 +765,39 @@ class TestHandlers(BaseSessionTest):
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9',
)
+ def test_add_retry_headers_sets_both_headers(self):
+ request = AWSRequest()
+ request.context['retries'] = {
+ 'invocation-id': 'abc-123',
+ 'attempt': 2,
+ 'max': 3,
+ }
+ handlers.add_retry_headers(request)
+ self.assertEqual(request.headers['amz-sdk-invocation-id'], 'abc-123')
+ self.assertEqual(
+ request.headers['amz-sdk-request'], 'attempt=2; max=3'
+ )
+
+ def test_request_created_on_synthesized_request_does_not_raise(self):
+ # s3transfer's functional tests emit ``request-created`` on an
+ # ``AWSRequest`` they build themselves, so no endpoint created the
+ # retries context first. With the new retry defaults the seeder runs
+ # before ``add_retry_headers``; it must not create a partial context
+ # that makes ``add_retry_headers`` raise.
+ with mock.patch('botocore.retries.standard.NEW_RETRIES_ENABLED', True):
+ client = self.session.create_client(
+ 's3', config=Config(retries={'mode': 'standard'})
+ )
+ request = AWSRequest(method='PUT', url='https://s3.amazonaws.com')
+ client.meta.events.emit(
+ 'request-created.s3.PutObject',
+ request=request,
+ operation_name='PutObject',
+ )
+ self.assertNotIn('retries', request.context)
+ self.assertNotIn('amz-sdk-invocation-id', request.headers)
+ self.assertNotIn('amz-sdk-request', request.headers)
+
def test_switch_host_with_param(self):
request = AWSRequest()
url = 'https://machinelearning.us-east-1.amazonaws.com'