Merge pull request #2484 from koshigoe/bugfix/check-none-in-s3-model-get_key
Avoid exception occur in `moto.s3.models.S3Backend.get_key`
This commit is contained in:
commit
16a0e93259
@ -1107,7 +1107,7 @@ class S3Backend(BaseBackend):
|
||||
key = key_version
|
||||
break
|
||||
|
||||
if part_number and key.multipart:
|
||||
if part_number and key and key.multipart:
|
||||
key = key.multipart.parts[part_number]
|
||||
|
||||
if isinstance(key, FakeKey):
|
||||
|
@ -1534,6 +1534,18 @@ def test_boto3_get_object():
|
||||
e.exception.response['Error']['Code'].should.equal('NoSuchKey')
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_boto3_get_missing_object_with_part_number():
|
||||
s3 = boto3.resource('s3', region_name='us-east-1')
|
||||
s3.create_bucket(Bucket="blah")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
s3.Object('blah', 'hello.txt').meta.client.head_object(
|
||||
Bucket='blah', Key='hello.txt', PartNumber=123)
|
||||
|
||||
e.exception.response['Error']['Code'].should.equal('404')
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_boto3_head_object_with_versioning():
|
||||
s3 = boto3.resource('s3', region_name='us-east-1')
|
||||
|
Loading…
Reference in New Issue
Block a user