File tree Expand file tree Collapse file tree 4 files changed +22
-0
lines changed Expand file tree Collapse file tree 4 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -1911,6 +1911,7 @@ def metadata(self, value):
19111911 :type value: dict
19121912 :param value: (Optional) The blob metadata to set.
19131913 """
1914+ value = {k : str (v ) for k , v in value .items ()}
19141915 self ._patch_property ("metadata" , value )
19151916
19161917 @property
Original file line number Diff line number Diff line change @@ -1366,6 +1366,7 @@ def labels(self, mapping):
13661366 existing = set ([k for k in self .labels .keys ()])
13671367 incoming = set ([k for k in mapping .keys ()])
13681368 self ._label_removals = self ._label_removals .union (existing .difference (incoming ))
1369+ mapping = {k : str (v ) for k , v in mapping .items ()}
13691370
13701371 # Actually update the labels on the object.
13711372 self ._patch_property ("labels" , copy .deepcopy (mapping ))
Original file line number Diff line number Diff line change @@ -2913,6 +2913,16 @@ def test_metadata_setter(self):
29132913 blob .metadata = METADATA
29142914 self .assertEqual (blob .metadata , METADATA )
29152915
2916+ def test_metadata_setter_w_nan (self ):
2917+ BLOB_NAME = "blob-name"
2918+ METADATA = {"foo" : float ("nan" )}
2919+ bucket = _Bucket ()
2920+ blob = self ._make_one (BLOB_NAME , bucket = bucket )
2921+ self .assertIsNone (blob .metadata )
2922+ blob .metadata = METADATA
2923+ value = blob .metadata ["foo" ]
2924+ self .assertIsInstance (value , str )
2925+
29162926 def test_metageneration (self ):
29172927 BUCKET = object ()
29182928 METAGENERATION = 42
Original file line number Diff line number Diff line change @@ -1651,6 +1651,16 @@ def test_labels_setter(self):
16511651 self .assertIsNot (bucket ._properties ["labels" ], LABELS )
16521652 self .assertIn ("labels" , bucket ._changes )
16531653
1654+ def test_labels_setter_with_nan (self ):
1655+ NAME = "name"
1656+ LABELS = {"color" : "red" , "foo" : float ("nan" )}
1657+ bucket = self ._make_one (name = NAME )
1658+
1659+ self .assertEqual (bucket .labels , {})
1660+ bucket .labels = LABELS
1661+ value = bucket .labels ["foo" ]
1662+ self .assertIsInstance (value , str )
1663+
16541664 def test_labels_setter_with_removal (self ):
16551665 # Make sure the bucket labels look correct and follow the expected
16561666 # public structure.
You can’t perform that action at this time.
0 commit comments