Thanks to visit codestin.com
Credit goes to github.com

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
5 changes: 3 additions & 2 deletions storage/google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1908,9 +1908,10 @@ def metadata(self, value):
See https://cloud.google.com/storage/docs/json_api/v1/objects

:type value: dict
:param value: (Optional) The blob metadata to set.
:param value: The blob metadata to set.
"""
value = {k: str(v) for k, v in value.items()}
if value is not None:
value = {k: str(v) for k, v in value.items()}
Copy link
Author

@IlyaFaer IlyaFaer Jan 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value has tag Optional, so it really looks like a regression
Do we need to do the same thing for bucket labels? I don't see Optional tag for them. Still, stringifying was added for them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the documentation is incorrect. The code is correct in that the property metadata is optional but should not be optional when setting this value.

Copy link
Author

@IlyaFaer IlyaFaer Jan 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've deleted Optional tag. As I see, it was added by some kind of a script

self._patch_property("metadata", value)

@property
Expand Down
10 changes: 10 additions & 0 deletions storage/tests/unit/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,16 @@ def test__get_writable_metadata_unwritable_field(self):
expected = {"name": name}
self.assertEqual(object_metadata, expected)

def test__set_metadata_to_none(self):
name = u"blob-name"
blob = self._make_one(name, bucket=None)
blob.storage_class = "NEARLINE"
blob.cache_control = "max-age=3600"

with mock.patch("google.cloud.storage.blob.Blob._patch_property") as patch_prop:
blob.metadata = None
patch_prop.assert_called_once_with("metadata", None)

def test__get_upload_arguments(self):
name = u"blob-name"
key = b"[pXw@,p@@AfBfrR3x-2b2SCHR,.?YwRO"
Expand Down