Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batched commands don't work #411

Open
oittaa opened this issue Feb 4, 2021 · 1 comment
Open

Batched commands don't work #411

oittaa opened this issue Feb 4, 2021 · 1 comment

Comments

@oittaa
Copy link

oittaa commented Feb 4, 2021

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.

@fsouza
Copy link
Owner

fsouza commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants