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

fix: address incorrect usage of request preconditions #366

Merged
merged 1 commit into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions google/cloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,9 @@ def rename_blob(
This method will first duplicate the data and then delete the
old blob. This means that with very large objects renaming
could be a very (temporarily) costly or a very slow operation.
If you need more control over the copy and deletion, instead
use `google.cloud.storage.blob.Blob.copy_to` and
`google.cloud.storage.blob.Blob.delete` directly.

:type blob: :class:`google.cloud.storage.blob.Blob`
:param blob: The blob to be renamed.
Expand Down Expand Up @@ -2079,25 +2082,29 @@ def rename_blob(
:param if_source_generation_match: (Optional) Makes the operation
conditional on whether the source
object's generation matches the
given value.
given value. Also used in the
delete request.

:type if_source_generation_not_match: long
:param if_source_generation_not_match: (Optional) Makes the operation
conditional on whether the source
object's generation does not match
the given value.
the given value. Also used in the
delete request.

:type if_source_metageneration_match: long
:param if_source_metageneration_match: (Optional) Makes the operation
conditional on whether the source
object's current metageneration
matches the given value.
matches the given value.Also used in the
delete request.

:type if_source_metageneration_not_match: long
:param if_source_metageneration_not_match: (Optional) Makes the operation
conditional on whether the source
object's current metageneration
does not match the given value.
Also used in the delete request.

:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
:param retry: (Optional) How to retry the RPC. A None value will disable retries.
Expand Down Expand Up @@ -2139,10 +2146,10 @@ def rename_blob(
blob.delete(
client=client,
timeout=timeout,
if_generation_match=if_generation_match,
if_generation_not_match=if_generation_not_match,
if_metageneration_match=if_metageneration_match,
if_metageneration_not_match=if_metageneration_not_match,
if_generation_match=if_source_generation_match,
if_generation_not_match=if_source_generation_not_match,
if_metageneration_match=if_source_metageneration_match,
if_metageneration_not_match=if_source_metageneration_not_match,
retry=retry,
)
return new_blob
Expand Down
13 changes: 8 additions & 5 deletions tests/unit/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,8 @@ def test_rename_blob_with_generation_match(self):
NEW_BLOB_NAME = "new-blob-name"
DATA = {"name": NEW_BLOB_NAME}
GENERATION_NUMBER = 6
METAGENERATION_NUMBER = 9
SOURCE_GENERATION_NUMBER = 7
SOURCE_METAGENERATION_NUMBER = 9

connection = _Connection(DATA)
client = _Client(connection)
Expand All @@ -1652,7 +1653,8 @@ def test_rename_blob_with_generation_match(self):
client=client,
timeout=42,
if_generation_match=GENERATION_NUMBER,
if_source_metageneration_not_match=METAGENERATION_NUMBER,
if_source_generation_match=SOURCE_GENERATION_NUMBER,
if_source_metageneration_not_match=SOURCE_METAGENERATION_NUMBER,
)

self.assertIs(renamed_blob.bucket, bucket)
Expand All @@ -1668,7 +1670,8 @@ def test_rename_blob_with_generation_match(self):
kw["query_params"],
{
"ifGenerationMatch": GENERATION_NUMBER,
"ifSourceMetagenerationNotMatch": METAGENERATION_NUMBER,
"ifSourceGenerationMatch": SOURCE_GENERATION_NUMBER,
"ifSourceMetagenerationNotMatch": SOURCE_METAGENERATION_NUMBER,
},
)
self.assertEqual(kw["timeout"], 42)
Expand All @@ -1677,10 +1680,10 @@ def test_rename_blob_with_generation_match(self):
blob.delete.assert_called_once_with(
client=client,
timeout=42,
if_generation_match=GENERATION_NUMBER,
if_generation_match=SOURCE_GENERATION_NUMBER,
if_generation_not_match=None,
if_metageneration_match=None,
if_metageneration_not_match=None,
if_metageneration_not_match=SOURCE_METAGENERATION_NUMBER,
retry=DEFAULT_RETRY_IF_GENERATION_SPECIFIED,
)

Expand Down