From 99c1a0b0f00997b904a479e42a09828dcabe68a1 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Tue, 13 Jan 2015 16:57:06 -0800 Subject: [PATCH] Preserving indexed=False from parsed proto `Value`s. Fixes #513. --- gcloud/datastore/helpers.py | 10 ++++++++-- gcloud/datastore/test_helpers.py | 12 +++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gcloud/datastore/helpers.py b/gcloud/datastore/helpers.py index afee07891a1f5..745697c844e75 100644 --- a/gcloud/datastore/helpers.py +++ b/gcloud/datastore/helpers.py @@ -16,6 +16,7 @@ The non-private functions are part of the API. """ + __all__ = ('entity_from_protobuf', 'key_from_protobuf') import calendar @@ -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 diff --git a/gcloud/datastore/test_helpers.py b/gcloud/datastore/test_helpers.py index c195373851e96..6b40f33b6b0c8 100644 --- a/gcloud/datastore/test_helpers.py +++ b/gcloud/datastore/test_helpers.py @@ -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)