Skip to content

Commit 0576e0b

Browse files
feat(storage): support delete_source_objects in compose API
Implements the delete_source_objects parameter in Blob.compose() to allow automatic deletion of source objects upon successful composition. Also adds unit and system tests to verify the new parameter and handles PR feedback. Reference PR: googleapis/google-cloud-java#12873 Co-authored-by: nidhiii-27 <224584462+nidhiii-27@users.noreply.github.com>
1 parent fc96097 commit 0576e0b

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

packages/google-cloud-storage/tests/system/test_blob.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -857,25 +857,20 @@ def test_blob_compose_delete_source_objects(shared_bucket, blobs_to_delete):
857857
payload_1 = b"AAA\n"
858858
source_1 = shared_bucket.blob("source-1-delete")
859859
source_1.upload_from_string(payload_1)
860+
blobs_to_delete.append(source_1)
860861

861862
payload_2 = b"BBB\n"
862863
source_2 = shared_bucket.blob("source-2-delete")
863864
source_2.upload_from_string(payload_2)
865+
blobs_to_delete.append(source_2)
864866

865867
destination = shared_bucket.blob("destination-delete")
866868
destination.compose([source_1, source_2], delete_source_objects=True)
867869
blobs_to_delete.append(destination)
868870

869871
assert destination.download_as_bytes() == payload_1 + payload_2
870-
871-
try:
872-
assert not source_1.exists()
873-
assert not source_2.exists()
874-
finally:
875-
if source_1.exists():
876-
blobs_to_delete.append(source_1)
877-
if source_2.exists():
878-
blobs_to_delete.append(source_2)
872+
assert not source_1.exists()
873+
assert not source_2.exists()
879874

880875

881876
def test_blob_compose_new_blob_wo_content_type(shared_bucket, blobs_to_delete):

packages/google-cloud-storage/tests/unit/test_blob.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4491,7 +4491,9 @@ def test_compose_w_delete_source_objects(self):
44914491
client._post_resource.return_value = api_response
44924492
bucket = _Bucket(client=client)
44934493
source_1 = self._make_one(source_1_name, bucket=bucket)
4494+
source_1._properties["generation"] = 1
44944495
source_2 = self._make_one(source_2_name, bucket=bucket)
4496+
source_2._properties["generation"] = 2
44954497
destination = self._make_one(destination_name, bucket=bucket)
44964498
destination.content_type = content_type
44974499

0 commit comments

Comments
 (0)