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

Returned future result in S3Transfer's download and upload #3316

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions boto3/s3/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ def upload_file(
.. seealso::
:py:meth:`S3.Client.upload_file`
:py:meth:`S3.Client.upload_fileobj`

:returns: The result of the specific manager's upload function.
"""
if not isinstance(filename, str):
raise ValueError('Filename must be a string')
Expand All @@ -285,7 +287,7 @@ def upload_file(
filename, bucket, key, extra_args, subscribers
)
try:
future.result()
return future.result()
# If a client error was raised, add the backwards compatibility layer
# that raises a S3UploadFailedError. These specific errors were only
# ever thrown for upload_parts but now can be thrown for any related
Expand All @@ -308,6 +310,8 @@ def download_file(
.. seealso::
:py:meth:`S3.Client.download_file`
:py:meth:`S3.Client.download_fileobj`

:returns: The result of the specific manager's download function.
"""
if not isinstance(filename, str):
raise ValueError('Filename must be a string')
Expand All @@ -317,7 +321,7 @@ def download_file(
bucket, key, filename, extra_args, subscribers
)
try:
future.result()
return future.result()
# This is for backwards compatibility where when retries are
# exceeded we need to throw the same error from boto3 instead of
# s3transfer's built in RetriesExceededError as current users are
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/s3/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,26 @@ def assert_callback_wrapped_in_subscriber(self, call_args):

def test_upload_file(self):
extra_args = {'ACL': 'public-read'}
self.transfer.upload_file(
upload_metadata = self.transfer.upload_file(
'smallfile', 'bucket', 'key', extra_args=extra_args
)
self.manager.upload.assert_called_with(
'smallfile', 'bucket', 'key', extra_args, None
)
self.assertIsNotNone(upload_metadata)

def test_download_file(self):
extra_args = {
'SSECustomerKey': 'foo',
'SSECustomerAlgorithm': 'AES256',
}
self.transfer.download_file(
download_metadata = self.transfer.download_file(
'bucket', 'key', '/tmp/smallfile', extra_args=extra_args
)
self.manager.download.assert_called_with(
'bucket', 'key', '/tmp/smallfile', extra_args, None
)
self.assertIsNotNone(download_metadata)

def test_upload_wraps_callback(self):
self.transfer.upload_file(
Expand Down