Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8e21a7f

Browse filesBrowse files
authored
feat: expose finalized_time in blob.py applicable for GET_OBJECT in ZB (#1719)
feat: expose finalized_time in blob.py applicable for GET_OBJECT in ZB
1 parent 721ea2d commit 8e21a7f
Copy full SHA for 8e21a7f

File tree

Expand file treeCollapse file tree

3 files changed

+37
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+37
-0
lines changed
Open diff view settings
Collapse file

‎google/cloud/storage/blob.py‎

Copy file name to clipboardExpand all lines: google/cloud/storage/blob.py
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5034,6 +5034,19 @@ def hard_delete_time(self):
50345034
if hard_delete_time is not None:
50355035
return _rfc3339_nanos_to_datetime(hard_delete_time)
50365036

5037+
@property
5038+
def finalized_time(self):
5039+
"""If this object has been soft-deleted, returns the time at which it will be permanently deleted.
5040+
5041+
:rtype: :class:`datetime.datetime` or ``NoneType``
5042+
:returns:
5043+
(readonly) The time that the object will be permanently deleted.
5044+
Note this property is only set for soft-deleted objects.
5045+
"""
5046+
finalize_time = self._properties.get("finalizedTime", None)
5047+
if finalize_time is not None:
5048+
return _rfc3339_nanos_to_datetime(finalize_time)
5049+
50375050

50385051
def _get_host_name(connection):
50395052
"""Returns the host name from the given connection.
Collapse file

‎samples/snippets/storage_get_metadata.py‎

Copy file name to clipboardExpand all lines: samples/snippets/storage_get_metadata.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def blob_metadata(bucket_name, blob_name):
3434
blob = bucket.get_blob(blob_name)
3535

3636
print(f"Blob: {blob.name}")
37+
print(f"Blob finalization: {blob.finalized_time}")
3738
print(f"Bucket: {blob.bucket.name}")
3839
print(f"Storage class: {blob.storage_class}")
3940
print(f"ID: {blob.id}")
Collapse file

‎tests/unit/test_blob.py‎

Copy file name to clipboardExpand all lines: tests/unit/test_blob.py
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,29 @@ def test__set_properties_w_kms_key_name(self):
228228
)
229229
self._set_properties_helper(kms_key_name=kms_resource)
230230

231+
def test_finalized_time_property_is_none(self):
232+
BLOB_NAME = "blob-name"
233+
bucket = _Bucket()
234+
blob = self._make_one(BLOB_NAME, bucket=bucket)
235+
self.assertIsNone(blob.finalized_time)
236+
237+
def test_finalized_time_property_is_not_none(self):
238+
from google.cloud.storage import blob as blob_module
239+
240+
BLOB_NAME = "blob-name"
241+
bucket = _Bucket()
242+
blob = self._make_one(BLOB_NAME, bucket=bucket)
243+
244+
timestamp = "2024-07-29T12:34:56.123456Z"
245+
blob._properties["finalizedTime"] = timestamp
246+
247+
mock_datetime = mock.Mock()
248+
with mock.patch.object(
249+
blob_module, "_rfc3339_nanos_to_datetime", return_value=mock_datetime
250+
) as mocked:
251+
self.assertEqual(blob.finalized_time, mock_datetime)
252+
mocked.assert_called_once_with(timestamp)
253+
231254
def test_chunk_size_ctor(self):
232255
from google.cloud.storage.blob import Blob
233256

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.