diff --git a/gcloud/datastore/helpers.py b/gcloud/datastore/helpers.py index c8927bf2beea..91ea9af3fba0 100644 --- a/gcloud/datastore/helpers.py +++ b/gcloud/datastore/helpers.py @@ -222,6 +222,10 @@ def _set_protobuf_value(value_pb, val): :class:`gcloud.datastore.entity.Entity`, :param val: The value to be assigned. """ + if val is None: + value_pb.Clear() + return + attr, val = _get_protobuf_attribute_and_value(val) if attr == 'key_value': value_pb.key_value.CopyFrom(val) diff --git a/gcloud/datastore/test_helpers.py b/gcloud/datastore/test_helpers.py index c2c8aae45933..43879fc79aa9 100644 --- a/gcloud/datastore/test_helpers.py +++ b/gcloud/datastore/test_helpers.py @@ -361,6 +361,25 @@ def test_key(self): value = pb.key_value self.assertEqual(value, key.to_protobuf()) + def test_none(self): + from gcloud.datastore.entity import Entity + + entity = Entity() + pb = self._makePB() + + self._callFUT(pb, False) + self._callFUT(pb, 3.1415926) + self._callFUT(pb, 42) + self._callFUT(pb, (1 << 63) - 1) + self._callFUT(pb, 'str') + self._callFUT(pb, b'str') + self._callFUT(pb, u'str') + self._callFUT(pb, entity) + self._callFUT(pb, [u'a', 0, 3.14]) + + self._callFUT(pb, None) + self.assertEqual(len(pb.ListFields()), 0) + def test_bool(self): pb = self._makePB() self._callFUT(pb, False)