File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,9 @@ def rename_blob(
20222022
This method will first duplicate the data and then delete the
20232023
old blob. This means that with very large objects renaming
20242024
could be a very (temporarily) costly or a very slow operation.
2025+
If you need more control over the copy and deletion, instead
2026+
use `google.cloud.storage.blob.Blob.copy_to` and
2027+
`google.cloud.storage.blob.Blob.delete` directly.
20252028
20262029
:type blob: :class:`google.cloud.storage.blob.Blob`
20272030
:param blob: The blob to be renamed.
@@ -2079,25 +2082,29 @@ def rename_blob(
20792082
:param if_source_generation_match: (Optional) Makes the operation
20802083
conditional on whether the source
20812084
object's generation matches the
2082-
given value.
2085+
given value. Also used in the
2086+
delete request.
20832087
20842088
:type if_source_generation_not_match: long
20852089
:param if_source_generation_not_match: (Optional) Makes the operation
20862090
conditional on whether the source
20872091
object's generation does not match
2088-
the given value.
2092+
the given value. Also used in the
2093+
delete request.
20892094
20902095
:type if_source_metageneration_match: long
20912096
:param if_source_metageneration_match: (Optional) Makes the operation
20922097
conditional on whether the source
20932098
object's current metageneration
2094-
matches the given value.
2099+
matches the given value.Also used in the
2100+
delete request.
20952101
20962102
:type if_source_metageneration_not_match: long
20972103
:param if_source_metageneration_not_match: (Optional) Makes the operation
20982104
conditional on whether the source
20992105
object's current metageneration
21002106
does not match the given value.
2107+
Also used in the delete request.
21012108
21022109
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
21032110
:param retry: (Optional) How to retry the RPC. A None value will disable retries.
@@ -2139,10 +2146,10 @@ def rename_blob(
21392146
blob.delete(
21402147
client=client,
21412148
timeout=timeout,
2142-
if_generation_match=if_generation_match,
2143-
if_generation_not_match=if_generation_not_match,
2144-
if_metageneration_match=if_metageneration_match,
2145-
if_metageneration_not_match=if_metageneration_not_match,
2149+
if_generation_match=if_source_generation_match,
2150+
if_generation_not_match=if_source_generation_not_match,
2151+
if_metageneration_match=if_source_metageneration_match,
2152+
if_metageneration_not_match=if_source_metageneration_not_match,
21462153
retry=retry,
21472154
)
21482155
return new_blob
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,8 @@ def test_rename_blob_with_generation_match(self):
16391639
NEW_BLOB_NAME = "new-blob-name"
16401640
DATA = {"name": NEW_BLOB_NAME}
16411641
GENERATION_NUMBER = 6
1642-
METAGENERATION_NUMBER = 9
1642+
SOURCE_GENERATION_NUMBER = 7
1643+
SOURCE_METAGENERATION_NUMBER = 9
16431644

16441645
connection = _Connection(DATA)
16451646
client = _Client(connection)
@@ -1652,7 +1653,8 @@ def test_rename_blob_with_generation_match(self):
16521653
client=client,
16531654
timeout=42,
16541655
if_generation_match=GENERATION_NUMBER,
1655-
if_source_metageneration_not_match=METAGENERATION_NUMBER,
1656+
if_source_generation_match=SOURCE_GENERATION_NUMBER,
1657+
if_source_metageneration_not_match=SOURCE_METAGENERATION_NUMBER,
16561658
)
16571659

16581660
self.assertIs(renamed_blob.bucket, bucket)
@@ -1668,7 +1670,8 @@ def test_rename_blob_with_generation_match(self):
16681670
kw["query_params"],
16691671
{
16701672
"ifGenerationMatch": GENERATION_NUMBER,
1671-
"ifSourceMetagenerationNotMatch": METAGENERATION_NUMBER,
1673+
"ifSourceGenerationMatch": SOURCE_GENERATION_NUMBER,
1674+
"ifSourceMetagenerationNotMatch": SOURCE_METAGENERATION_NUMBER,
16721675
},
16731676
)
16741677
self.assertEqual(kw["timeout"], 42)
@@ -1677,10 +1680,10 @@ def test_rename_blob_with_generation_match(self):
16771680
blob.delete.assert_called_once_with(
16781681
client=client,
16791682
timeout=42,
1680-
if_generation_match=GENERATION_NUMBER,
1683+
if_generation_match=SOURCE_GENERATION_NUMBER,
16811684
if_generation_not_match=None,
16821685
if_metageneration_match=None,
1683-
if_metageneration_not_match=None,
1686+
if_metageneration_not_match=SOURCE_METAGENERATION_NUMBER,
16841687
retry=DEFAULT_RETRY_IF_GENERATION_SPECIFIED,
16851688
)
16861689

0 commit comments

Comments
 (0)