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:
Mike Grima 2019-10-16 10:29:19 -07:00 committed by GitHub
commit 16a0e93259
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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):

View File

@ -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')