Skip to content

Commit

Permalink
Pass operation name to awscrt.s3 (#309)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Nate Prewitt <nate.prewitt@gmail.com>
  • Loading branch information
graebm and nateprewitt authored Jun 24, 2024
1 parent 6461de3 commit 81a0c70
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-awscrt-54174.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "``awscrt``",
"description": "Pass operation name to awscrt.s3 to improve error handling."
}
8 changes: 8 additions & 0 deletions s3transfer/crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,14 @@ def _default_get_make_request_args(
),
'on_progress': self.get_crt_callback(future, 'progress'),
}

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

if is_s3express_bucket(call_args.bucket):
make_request_args['signing_config'] = AwsSigningConfig(
algorithm=AwsSigningAlgorithm.V4_S3EXPRESS
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 @@ -549,6 +549,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
14 changes: 14 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,17 @@ 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 81a0c70

Please sign in to comment.