Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit edd0137

Browse files
author
IlyaFaer
committed
refactor(storage): deprecate preserve_acl arg in copy_blob() method
1 parent 5c04eef commit edd0137

2 files changed

Lines changed: 26 additions & 19 deletions

File tree

google/cloud/storage/bucket.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ def copy_blob(
12441244
destination_bucket,
12451245
new_name=None,
12461246
client=None,
1247-
preserve_acl=True,
1247+
preserve_acl=None,
12481248
source_generation=None,
12491249
timeout=_DEFAULT_TIMEOUT,
12501250
):
@@ -1268,8 +1268,8 @@ def copy_blob(
12681268
to the ``client`` stored on the current bucket.
12691269
12701270
:type preserve_acl: bool
1271-
:param preserve_acl: (Optional) Copies ACL from old blob to new blob.
1272-
Default: True.
1271+
:param preserve_acl: DEPRECATED. (Optional) Copies ACL from old blob to
1272+
new blob. Default: True.
12731273
12741274
:type source_generation: long
12751275
:param source_generation: (Optional) The generation of the blob to be
@@ -1307,8 +1307,13 @@ def copy_blob(
13071307
timeout=timeout,
13081308
)
13091309

1310-
if not preserve_acl:
1311-
new_blob.acl.save(acl={}, client=client, timeout=timeout)
1310+
if preserve_acl is not None:
1311+
warnings.warn(
1312+
"preserve_acl arg is deprecated and will be removed in future."
1313+
"Do a subsequent ACL update instead.",
1314+
PendingDeprecationWarning,
1315+
stacklevel=1,
1316+
)
13121317

13131318
new_blob._set_properties(copy_result)
13141319
return new_blob

tests/unit/test_bucket.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,29 +1144,31 @@ def test_copy_blobs_preserve_acl(self):
11441144
dest = self._make_one(client=client, name=DEST)
11451145
blob = self._make_blob(SOURCE, BLOB_NAME)
11461146

1147-
new_blob = source.copy_blob(
1148-
blob, dest, NEW_NAME, client=client, preserve_acl=False
1149-
)
1147+
with mock.patch("warnings.warn") as warn:
1148+
new_blob = source.copy_blob(
1149+
blob, dest, NEW_NAME, client=client, preserve_acl=False
1150+
)
1151+
warn.assert_called_once_with(
1152+
"preserve_acl arg is deprecated and will be removed in future."
1153+
"Do a subsequent ACL update instead.",
1154+
PendingDeprecationWarning,
1155+
stacklevel=1,
1156+
)
11501157

11511158
self.assertIs(new_blob.bucket, dest)
11521159
self.assertEqual(new_blob.name, NEW_NAME)
11531160
self.assertIsInstance(new_blob.acl, ObjectACL)
11541161

1155-
kw1, kw2 = connection._requested
11561162
COPY_PATH = "/b/{}/o/{}/copyTo/b/{}/o/{}".format(
11571163
SOURCE, BLOB_NAME, DEST, NEW_NAME
11581164
)
1159-
NEW_BLOB_PATH = "/b/{}/o/{}".format(DEST, NEW_NAME)
11601165

1161-
self.assertEqual(kw1["method"], "POST")
1162-
self.assertEqual(kw1["path"], COPY_PATH)
1163-
self.assertEqual(kw1["query_params"], {})
1164-
self.assertEqual(kw1["timeout"], self._get_default_timeout())
1165-
1166-
self.assertEqual(kw2["method"], "PATCH")
1167-
self.assertEqual(kw2["path"], NEW_BLOB_PATH)
1168-
self.assertEqual(kw2["query_params"], {"projection": "full"})
1169-
self.assertEqual(kw2["timeout"], self._get_default_timeout())
1166+
self.assertEqual(connection._requested[0]["method"], "POST")
1167+
self.assertEqual(connection._requested[0]["path"], COPY_PATH)
1168+
self.assertEqual(connection._requested[0]["query_params"], {})
1169+
self.assertEqual(
1170+
connection._requested[0]["timeout"], self._get_default_timeout()
1171+
)
11701172

11711173
def test_copy_blobs_w_name_and_user_project(self):
11721174
SOURCE = "source"

0 commit comments

Comments
 (0)