Skip to content

Commit f048be1

Browse files
authored
fix: set custom_time on uploads (#374)
The custom_time property was incorrectly not included as a field that could be set on object upload. Fixes #372
1 parent 5c60d24 commit f048be1

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

google/cloud/storage/blob.py

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"contentLanguage",
9797
_CONTENT_TYPE_FIELD,
9898
"crc32c",
99+
"customTime",
99100
"md5Hash",
100101
"metadata",
101102
"name",
@@ -1530,6 +1531,7 @@ def _get_writable_metadata(self):
15301531
* ``contentLanguage``
15311532
* ``contentType``
15321533
* ``crc32c``
1534+
* ``customTime``
15331535
* ``md5Hash``
15341536
* ``metadata``
15351537
* ``name``

tests/system/test_system.py

+13
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,19 @@ def test_upload_blob_owner(self):
10271027
owner = same_blob.owner
10281028
self.assertIn(user_email, owner["entity"])
10291029

1030+
def test_upload_blob_custom_time(self):
1031+
blob = self.bucket.blob("CustomTimeBlob")
1032+
file_contents = b"Hello World"
1033+
current_time = datetime.datetime.now()
1034+
blob.custom_time = current_time
1035+
blob.upload_from_string(file_contents)
1036+
self.case_blobs_to_delete.append(blob)
1037+
1038+
same_blob = self.bucket.blob("CustomTimeBlob")
1039+
same_blob.reload(projection="full")
1040+
custom_time = same_blob.custom_time.replace(tzinfo=None)
1041+
self.assertEqual(custom_time, current_time)
1042+
10301043
def test_blob_crc32_md5_hash(self):
10311044
blob = self.bucket.blob("MyBuffer")
10321045
file_contents = b"Hello World"

0 commit comments

Comments
 (0)