Set version_id to null without bucket versioning (#4574)

This commit is contained in:
Jordan Sanders 2021-11-15 14:25:34 -06:00 committed by GitHub
parent 846c1d22a8
commit 7664cab828
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 1 deletions

View File

@ -1595,7 +1595,7 @@ class S3Backend(BaseBackend):
storage=storage, storage=storage,
etag=etag, etag=etag,
is_versioned=bucket.is_versioned, is_versioned=bucket.is_versioned,
version_id=str(uuid.uuid4()) if bucket.is_versioned else None, version_id=str(uuid.uuid4()) if bucket.is_versioned else "null",
multipart=multipart, multipart=multipart,
encryption=encryption, encryption=encryption,
kms_key_id=kms_key_id, kms_key_id=kms_key_id,

View File

@ -1372,6 +1372,63 @@ def test_delete_keys():
keys[0].name.should.equal("file1") keys[0].name.should.equal("file1")
@mock_s3
def test_delete_versioned_objects():
s3 = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
bucket = "test"
key = "test"
s3.create_bucket(Bucket=bucket)
s3.put_object(Bucket=bucket, Key=key, Body=b"")
s3.put_bucket_versioning(
Bucket=bucket, VersioningConfiguration={"Status": "Enabled"},
)
objects = s3.list_objects_v2(Bucket=bucket).get("Contents")
versions = s3.list_object_versions(Bucket=bucket).get("Versions")
delete_markers = s3.list_object_versions(Bucket=bucket).get("DeleteMarkers")
objects.shouldnt.be.empty
versions.shouldnt.be.empty
delete_markers.should.be.none
s3.delete_object(Bucket=bucket, Key=key)
objects = s3.list_objects_v2(Bucket=bucket).get("Contents")
versions = s3.list_object_versions(Bucket=bucket).get("Versions")
delete_markers = s3.list_object_versions(Bucket=bucket).get("DeleteMarkers")
objects.should.be.none
versions.shouldnt.be.empty
delete_markers.shouldnt.be.empty
s3.delete_object(
Bucket=bucket, Key=key, VersionId=versions[0].get("VersionId"),
)
objects = s3.list_objects_v2(Bucket=bucket).get("Contents")
versions = s3.list_object_versions(Bucket=bucket).get("Versions")
delete_markers = s3.list_object_versions(Bucket=bucket).get("DeleteMarkers")
objects.should.be.none
versions.should.be.none
delete_markers.shouldnt.be.empty
s3.delete_object(
Bucket=bucket, Key=key, VersionId=delete_markers[0].get("VersionId"),
)
objects = s3.list_objects_v2(Bucket=bucket).get("Contents")
versions = s3.list_object_versions(Bucket=bucket).get("Versions")
delete_markers = s3.list_object_versions(Bucket=bucket).get("DeleteMarkers")
objects.should.be.none
versions.should.be.none
delete_markers.should.be.none
# Has boto3 equivalent # Has boto3 equivalent
@mock_s3_deprecated @mock_s3_deprecated
def test_delete_keys_invalid(): def test_delete_keys_invalid():