Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass operation name to awscrt.s3 #309

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
nateprewitt marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 8 additions & 0 deletions s3transfer/crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,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 @@ -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
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
Loading