Skip to content

feat(storage): update compose sample to support deleteSourceObjects option#14323

Draft
nidhiii-27 wants to merge 3 commits into
mainfrom
feat/python-compose-delete-sources
Draft

feat(storage): update compose sample to support deleteSourceObjects option#14323
nidhiii-27 wants to merge 3 commits into
mainfrom
feat/python-compose-delete-sources

Conversation

@nidhiii-27

Copy link
Copy Markdown
Contributor

Update compose_file snippet to support delete_source_objects option.
Add corresponding system integration tests.

[Generated-by: AI]

…ption

Update compose_file snippet to support delete_source_objects option.
Add corresponding system integration tests.

[Generated-by: AI]
@product-auto-label product-auto-label Bot added api: storage Issues related to the Cloud Storage API. samples Issues that are directly related to samples. labels Jun 16, 2026
@nidhiii-27 nidhiii-27 added ai-generated storage-sample-architect and removed api: storage Issues related to the Cloud Storage API. samples Issues that are directly related to samples. labels Jun 16, 2026
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Jun 16, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds an optional delete_source_objects parameter to the compose_file function, enabling automatic deletion of source blobs after composition. It also updates the test suite to verify this behavior. The review feedback suggests updating the function's docstring to document this new parameter and simplifying the test by replacing an unnecessary local temporary file with a unique string.

destination_blob_name,
delete_source_objects=False,
):
"""Concatenate source blobs into destination blob."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The docstring should be updated to reflect the new capability of optionally deleting the source objects.

Suggested change
"""Concatenate source blobs into destination blob."""
"""Concatenate source blobs into destination blob and optionally delete sources."""

Comment on lines +704 to +713
with tempfile.NamedTemporaryFile() as dest_file:
destination = storage_compose_file.compose_file(
test_bucket.name,
source_files[0],
source_files[1],
dest_file.name,
delete_source_objects=True,
)
composed = destination.download_as_bytes()
assert composed.decode("utf-8") == source_files[0] + source_files[1]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using tempfile.NamedTemporaryFile is unnecessary here because compose_file only interacts with GCS blobs and does not read from or write to the local filesystem. We can simplify this by using a unique string for the destination blob name, avoiding the overhead of creating and deleting a temporary file on disk.

    dest_blob_name = f"test_compose_dest_{uuid.uuid4().hex}"
    destination = storage_compose_file.compose_file(
        test_bucket.name,
        source_files[0],
        source_files[1],
        dest_blob_name,
        delete_source_objects=True,
    )
    composed = destination.download_as_bytes()
    assert composed.decode("utf-8") == source_files[0] + source_files[1]

@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated api: storage Issues related to the Cloud Storage API. samples Issues that are directly related to samples. storage-sample-architect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant