Skip to content
Closed
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
15 changes: 12 additions & 3 deletions storage/google/cloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def copy_blob(
destination_bucket,
new_name=None,
client=None,
preserve_acl=True,
preserve_acl=None,
source_generation=None,
):
"""Copy the given blob to the given bucket, optionally with a new name.
Expand All @@ -1088,7 +1088,9 @@ def copy_blob(

:type preserve_acl: bool
:param preserve_acl: Optional. Copies ACL from old blob to new blob.
Default: True.
Default: None. Deprecated: this argument is no longer
affecting anything and will be removed in a future release.
Please update the blob's ACL manually.

:type source_generation: long
:param source_generation: Optional. The generation of the blob to be
Expand Down Expand Up @@ -1118,7 +1120,14 @@ def copy_blob(
_target_object=new_blob,
)

if not preserve_acl:
if preserve_acl is not None:
warnings.warn(
"The 'preserve_acl' argument is deprecated. For forward compatibility, "
"please update the blob's ACL manually.",
DeprecationWarning,
stacklevel=2,
)
if not preserve_acl and preserve_acl is not None:
new_blob.acl.save(acl={}, client=client)

new_blob._set_properties(copy_result)
Expand Down
10 changes: 9 additions & 1 deletion storage/tests/unit/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,8 @@ def test_copy_blobs_source_generation(self):
self.assertEqual(kw["path"], COPY_PATH)
self.assertEqual(kw["query_params"], {"sourceGeneration": GENERATION})

def test_copy_blobs_preserve_acl(self):
@mock.patch("warnings.warn")
def test_copy_blobs_preserve_acl_deprecated(self, mock_warn):
from google.cloud.storage.acl import ObjectACL

SOURCE = "source"
Expand All @@ -1170,6 +1171,13 @@ def test_copy_blobs_preserve_acl(self):
blob, dest, NEW_NAME, client=client, preserve_acl=False
)

mock_warn.assert_called_with(
"The 'preserve_acl' argument is deprecated. For forward compatibility, "
"please update the blob's ACL manually.",
DeprecationWarning,
stacklevel=2,
)

self.assertIs(new_blob.bucket, dest)
self.assertEqual(new_blob.name, NEW_NAME)
self.assertIsInstance(new_blob.acl, ObjectACL)
Expand Down