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

missing ActualObjectSize in s3.Object.get() response when requesting partial content with excess length #2981

Closed
jcushman opened this issue May 10, 2020 · 1 comment · Fixed by #3421

Comments

@jcushman
Copy link

When s3.Object.get() is called with an invalid range header, the Error response dict is missing the ActualObjectSize value, which is necessary to handle the error in client code.

For an example of why this response value is useful, see this smart_open PR, where ActualObjectSize is needed to avoid redundant API queries during seek().

This issue is related to #2964, but I am filing separately since that one could easily be fixed without fixing this one.

Expected behavior using live S3

In [1]: import boto3, botocore

In [3]: from pprint import pprint

In [4]: try:
   ...:     boto3.resource('s3').Object('mybucket', 'test.txt').get(Range="bytes=10000-")
   ...: except botocore.client.ClientError as e:
   ...:     pprint(e.response)
   ...:
{'Error': {'ActualObjectSize': '4',
           'Code': 'InvalidRange',
           'Message': 'The requested range is not satisfiable',
           'RangeRequested': 'bytes=10000-'},
 'ResponseMetadata': {'HTTPHeaders': {'content-type': 'application/xml',
                                      'date': 'Sun, 10 May 2020 18:14:10 GMT',
                                      'server': 'AmazonS3',
                                      'transfer-encoding': 'chunked',
                                      'x-amz-id-2': '...',
                                      'x-amz-request-id': '...'},
                      'HTTPStatusCode': 416,
                      'HostId': '...',
                      'RequestId': '...',
                      'RetryAttempts': 1}}

moto behavior

In [6]: with mock_s3():
   ...:     ...
   ...:     try:
   ...:         boto3.resource('s3').Object('mybucket', 'test.txt').get(Range="bytes=10000-")
   ...:     except botocore.client.ClientError as e:
   ...:         pprint(e.response)
   ...:
{'Error': {'Code': '416', 'Message': 'Requested Range Not Satisfiable'},
 'ResponseMetadata': {'HTTPHeaders': {},
                      'HTTPStatusCode': 416,
                      'HostId': '',
                      'RequestId': '',
                      'RetryAttempts': 0}}

Versions

moto==1.3.14, master
boto==2.49.0
boto3==1.13.0
botocore==1.16.0

@bblommers
Copy link
Collaborator

This is now partof moto >= 1.3.16.dev79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants