diff --git a/storage/google/cloud/storage/bucket.py b/storage/google/cloud/storage/bucket.py index 48ab09e23e4f..eabf883455ad 100644 --- a/storage/google/cloud/storage/bucket.py +++ b/storage/google/cloud/storage/bucket.py @@ -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. @@ -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 @@ -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) diff --git a/storage/tests/unit/test_bucket.py b/storage/tests/unit/test_bucket.py index de943339e200..52e9d38a1d80 100644 --- a/storage/tests/unit/test_bucket.py +++ b/storage/tests/unit/test_bucket.py @@ -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" @@ -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)