Skip to content

Commit

Permalink
fix(storage): fix blob metadata to None regression (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurov Ilya committed Feb 13, 2020
1 parent 8712da8 commit a834d1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions google/cloud/storage/blob.py
Expand Up @@ -1986,9 +1986,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()}
self._patch_property("metadata", value)

@property
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_blob.py
Expand Up @@ -1215,6 +1215,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

0 comments on commit a834d1b

Please sign in to comment.