Skip to content

Commit

Permalink
Preserving indexed=False from parsed proto Values.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Jan 14, 2015
1 parent 8a42ef5 commit 99c1a0b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 8 additions & 2 deletions gcloud/datastore/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
The non-private functions are part of the API.
"""

__all__ = ('entity_from_protobuf', 'key_from_protobuf')

import calendar
Expand Down Expand Up @@ -45,12 +46,17 @@ def entity_from_protobuf(pb):
:returns: The entity derived from the protobuf.
"""
key = key_from_protobuf(pb.key)
entity = Entity(key=key)
entity_props = {}
exclude_from_indexes = []

for property_pb in pb.property:
value = _get_value_from_property_pb(property_pb)
entity[property_pb.name] = value
entity_props[property_pb.name] = value
if not property_pb.value.indexed:
exclude_from_indexes.append(property_pb.name)

entity = Entity(key=key, exclude_from_indexes=exclude_from_indexes)
entity.update(entity_props)
return entity


Expand Down
12 changes: 11 additions & 1 deletion gcloud/datastore/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@ def test_it(self):
prop_pb = entity_pb.property.add()
prop_pb.name = 'foo'
prop_pb.value.string_value = 'Foo'

unindexed_prop_pb = entity_pb.property.add()
unindexed_prop_pb.name = 'bar'
unindexed_prop_pb.value.integer_value = 10
unindexed_prop_pb.value.indexed = False

entity = self._callFUT(entity_pb)
self.assertEqual(entity.kind, _KIND)
self.assertEqual(entity['foo'], 'Foo')
self.assertEqual(entity.exclude_from_indexes, frozenset(['bar']))
entity_props = dict(entity)
self.assertEqual(entity_props, {'foo': 'Foo', 'bar': 10})

# Also check the key.
key = entity.key
self.assertEqual(key.dataset_id, _DATASET_ID)
self.assertEqual(key.namespace, None)
Expand Down

0 comments on commit 99c1a0b

Please sign in to comment.