Skip to content

Commit

Permalink
Merge pull request #296 from lucemia/support-null-value
Browse files Browse the repository at this point in the history
#295 let entity save accept null value for attribute
  • Loading branch information
tseaver committed Oct 28, 2014
2 parents e1fd94f + a208132 commit 7d9bfb1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gcloud/datastore/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,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)
Expand Down
19 changes: 19 additions & 0 deletions gcloud/datastore/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,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)
Expand Down

0 comments on commit 7d9bfb1

Please sign in to comment.