Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storage): fix blob metadata to None regression #60

Merged
merged 1 commit into from Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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