Skip to content

Commit 11f6024

Browse files
authored
docs: add clarification to batch module (#1045)
* docs: add clarification to batch module * clarify constraints with batch * update docs
1 parent ab74673 commit 11f6024

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

google/cloud/storage/batch.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@
1313
# limitations under the License.
1414
"""Batch updates / deletes of storage buckets / blobs.
1515
16-
See https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch
16+
A batch request is a single standard HTTP request containing multiple Cloud Storage JSON API calls.
17+
Within this main HTTP request, there are multiple parts which each contain a nested HTTP request.
18+
The body of each part is itself a complete HTTP request, with its own verb, URL, headers, and body.
19+
20+
Note that Cloud Storage does not support batch operations for uploading or downloading.
21+
Additionally, the current batch design does not support library methods whose return values
22+
depend on the response payload. See more details in the [Sending Batch Requests official guide](https://cloud.google.com/storage/docs/batch).
23+
24+
Examples of situations when you might want to use the Batch module:
25+
``blob.patch()``
26+
``blob.update()``
27+
``blob.delete()``
28+
``bucket.delete_blob()``
29+
``bucket.patch()``
30+
``bucket.update()``
1731
"""
1832
from email.encoders import encode_noop
1933
from email.generator import Generator
@@ -131,6 +145,12 @@ def content(self):
131145
class Batch(Connection):
132146
"""Proxy an underlying connection, batching up change operations.
133147
148+
.. warning::
149+
150+
Cloud Storage does not support batch operations for uploading or downloading.
151+
Additionally, the current batch design does not support library methods whose
152+
return values depend on the response payload.
153+
134154
:type client: :class:`google.cloud.storage.client.Client`
135155
:param client: The client to use for making connections.
136156

google/cloud/storage/blob.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,6 +3450,10 @@ def rewrite(
34503450
If :attr:`user_project` is set on the bucket, bills the API request
34513451
to that project.
34523452
3453+
.. note::
3454+
3455+
``rewrite`` is not supported in a ``Batch`` context.
3456+
34533457
:type source: :class:`Blob`
34543458
:param source: blob whose contents will be rewritten into this blob.
34553459

google/cloud/storage/bucket.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,8 @@ def delete(
14821482
If ``force=True`` and the bucket contains more than 256 objects / blobs
14831483
this will cowardly refuse to delete the objects (or the bucket). This
14841484
is to prevent accidental bucket deletion and to prevent extremely long
1485-
runtime of this method.
1485+
runtime of this method. Also note that ``force=True`` is not supported
1486+
in a ``Batch`` context.
14861487
14871488
If :attr:`user_project` is set, bills the API request to that project.
14881489
@@ -1675,6 +1676,7 @@ def delete_blobs(
16751676
Called once for each blob raising
16761677
:class:`~google.cloud.exceptions.NotFound`;
16771678
otherwise, the exception is propagated.
1679+
Note that ``on_error`` is not supported in a ``Batch`` context.
16781680
16791681
:type client: :class:`~google.cloud.storage.client.Client`
16801682
:param client: (Optional) The client to use. If not passed, falls back
@@ -1801,6 +1803,8 @@ def copy_blob(
18011803
:param preserve_acl: DEPRECATED. This argument is not functional!
18021804
(Optional) Copies ACL from old blob to new blob.
18031805
Default: True.
1806+
Note that ``preserve_acl`` is not supported in a
1807+
``Batch`` context.
18041808
18051809
:type source_generation: long
18061810
:param source_generation: (Optional) The generation of the blob to be
@@ -1932,8 +1936,11 @@ def rename_blob(
19321936
old blob. This means that with very large objects renaming
19331937
could be a very (temporarily) costly or a very slow operation.
19341938
If you need more control over the copy and deletion, instead
1935-
use `google.cloud.storage.blob.Blob.copy_to` and
1936-
`google.cloud.storage.blob.Blob.delete` directly.
1939+
use ``google.cloud.storage.blob.Blob.copy_to`` and
1940+
``google.cloud.storage.blob.Blob.delete`` directly.
1941+
1942+
Also note that this method is not fully supported in a
1943+
``Batch`` context.
19371944
19381945
:type blob: :class:`google.cloud.storage.blob.Blob`
19391946
:param blob: The blob to be renamed.

samples/snippets/storage_batch_request.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828

2929

3030
def batch_request(bucket_name, prefix=None):
31-
"""Use a batch request to patch a list of objects with the given prefix in a bucket."""
31+
"""
32+
Use a batch request to patch a list of objects with the given prefix in a bucket.
33+
34+
Note that Cloud Storage does not support batch operations for uploading or downloading.
35+
Additionally, the current batch design does not support library methods whose return values
36+
depend on the response payload.
37+
See https://cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.batch
38+
"""
3239
# The ID of your GCS bucket
3340
# bucket_name = "my-bucket"
3441
# The prefix of the object paths

0 commit comments

Comments
 (0)