[GH-ISSUE #411] Batched commands don't work #78

Open
opened 2026-03-03 12:08:05 +03:00 by kerem · 1 comment
Owner

Originally created by @oittaa on GitHub (Feb 4, 2021).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/411

For example you can't delete multiple blobs in a batch like you can with the actual the Google service. Test case below.

import tempfile
from google.auth.credentials import AnonymousCredentials
from google.cloud import storage, exceptions

client = storage.Client(
    credentials=AnonymousCredentials(),
    project="test",
)
bucket = client.get_bucket("test-bucket")
blob = bucket.blob("key1")
blob.upload_from_string("test1")
blob = bucket.blob("key2")
blob.upload_from_string("test2")
try:
    with client.batch():
        bucket.delete_blob("key1")
        bucket.delete_blob("key2")
except exceptions.NotFound:
    pass

# List the Buckets
for bucket in client.list_buckets():
    print(f"Bucket: {bucket.name}\n")

    # List the Blobs in each Bucket
    for blob in bucket.list_blobs():
        print(f"Blob: {blob.name}")

        # Print the content of the Blob
        b = bucket.get_blob(blob.name)
        with tempfile.NamedTemporaryFile() as temp_file:
            s = b.download_to_filename(temp_file.name)
            temp_file.seek(0, 0)
            print(temp_file.read(), "\n")

Output:

Bucket: test-bucket

Blob: key1
b'test1'

Blob: key2
b'test2'

The expected result is an empty bucket.

Originally created by @oittaa on GitHub (Feb 4, 2021). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/411 For example you can't delete multiple blobs in a batch like you can with the actual the Google service. Test case below. ``` import tempfile from google.auth.credentials import AnonymousCredentials from google.cloud import storage, exceptions client = storage.Client( credentials=AnonymousCredentials(), project="test", ) bucket = client.get_bucket("test-bucket") blob = bucket.blob("key1") blob.upload_from_string("test1") blob = bucket.blob("key2") blob.upload_from_string("test2") try: with client.batch(): bucket.delete_blob("key1") bucket.delete_blob("key2") except exceptions.NotFound: pass # List the Buckets for bucket in client.list_buckets(): print(f"Bucket: {bucket.name}\n") # List the Blobs in each Bucket for blob in bucket.list_blobs(): print(f"Blob: {blob.name}") # Print the content of the Blob b = bucket.get_blob(blob.name) with tempfile.NamedTemporaryFile() as temp_file: s = b.download_to_filename(temp_file.name) temp_file.seek(0, 0) print(temp_file.read(), "\n") ``` Output: ``` Bucket: test-bucket Blob: key1 b'test1' Blob: key2 b'test2' ``` The expected result is an empty bucket.
Author
Owner

@fsouza commented on GitHub (Feb 15, 2021):

Indeed batch requests aren't supported currently. Marking as help wanted in case someone wants to contribute.

Relevant docs: https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch

<!-- gh-comment-id:779475943 --> @fsouza commented on GitHub (Feb 15, 2021): Indeed batch requests aren't supported currently. Marking as help wanted in case someone wants to contribute. Relevant docs: https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#78
No description provided.