Skip to content

Commit

Permalink
Pass operation name to awscrt.s3
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm committed Jun 21, 2024
1 parent 407232b commit 81e1de2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
15 changes: 12 additions & 3 deletions s3transfer/crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,13 +818,22 @@ def _default_get_make_request_args(
on_done_before_calls,
on_done_after_calls,
):
crt_request_type = getattr(
S3RequestType, request_type.upper(), S3RequestType.DEFAULT
)

# For DEFAULT requests, CRT requires the official S3 operation name.
# So transform string like "delete_object" -> "DeleteObject".
operation_name = None
if crt_request_type == S3RequestType.DEFAULT:
operation_name = ''.join(x.title() for x in request_type.split('_'))

make_request_args = {
'request': self._request_serializer.serialize_http_request(
request_type, future
),
'type': getattr(
S3RequestType, request_type.upper(), S3RequestType.DEFAULT
),
'type': crt_request_type,
'operation_name': operation_name,
'on_done': self.get_crt_callback(
future, 'done', on_done_before_calls, on_done_after_calls
),
Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def test_delete(self):
{
'request': mock.ANY,
'type': awscrt.s3.S3RequestType.DEFAULT,
'operation_name': "DeleteObject",
'on_progress': mock.ANY,
'on_done': mock.ANY,
},
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/test_crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import glob
import io
import os
from uuid import uuid4

from botocore.exceptions import ClientError

from s3transfer.subscribers import BaseSubscriber
from s3transfer.utils import OSUtils
Expand Down Expand Up @@ -404,6 +407,15 @@ def test_delete(self):
future.result()
self.assertTrue(self.object_not_exists('foo.txt'))

def test_delete_exception_no_such_bucket(self):
# delete() uses awscrt.s3.S3RequestType.DEFAULT under the hood.
# Test that CRT exceptions translate properly into the botocore exceptions.
transfer = self._create_s3_transfer()
with self.assertRaises(ClientError) as ctx:
future = transfer.delete(f"{self.bucket_name}-NONEXISTENT-{uuid4()}", "foo.txt")
future.result()
self.assertEqual(ctx.exception.__class__.__name__, 'NoSuchBucket')

def test_many_files_download(self):
transfer = self._create_s3_transfer()

Expand Down

0 comments on commit 81e1de2

Please sign in to comment.