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

#295 let entity save accept null value for attribute #296

Merged
merged 3 commits into from
Oct 28, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gcloud/datastore/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 @@ -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)

This comment was marked as spam.

self.assertEqual(len(pb.ListFields()), 0)

def test_bool(self):
pb = self._makePB()
self._callFUT(pb, False)
Expand Down