Skip to content

Commit 1463763

Browse files
committed
Upgrading Entity.property to properties map in datastore.
Towards googleapis#1288.
1 parent 6414b1f commit 1463763

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

gcloud/datastore/helpers.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ def _new_value_pb(entity_pb, name):
127127
:rtype: :class:`gcloud.datastore._generated.entity_pb2.Value`
128128
:returns: The new ``Value`` protobuf that was added to the entity.
129129
"""
130-
property_pb = entity_pb.property.add()
131-
property_pb.name = name
132-
return property_pb.value
130+
return entity_pb.properties.get_or_create(name)
133131

134132

135133
def _property_tuples(entity_pb):
@@ -142,8 +140,7 @@ def _property_tuples(entity_pb):
142140
:returns: An iterator that yields tuples of a name and ``Value``
143141
corresponding to properties on the entity.
144142
"""
145-
for property_pb in entity_pb.property:
146-
yield property_pb.name, property_pb.value
143+
return six.iteritems(entity_pb.properties)
147144

148145

149146
def entity_from_protobuf(pb):

gcloud/datastore/test_helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ def test_it(self):
2929
result = self._callFUT(entity_pb, name)
3030

3131
self.assertTrue(isinstance(result, entity_pb2.Value))
32-
self.assertEqual(len(entity_pb.property), 1)
33-
self.assertEqual(entity_pb.property[0].name, name)
34-
self.assertEqual(entity_pb.property[0].value, result)
32+
self.assertEqual(len(entity_pb.properties), 1)
33+
self.assertEqual(entity_pb.properties[name], result)
3534

3635

3736
class Test__property_tuples(unittest2.TestCase):
@@ -53,7 +52,8 @@ def test_it(self):
5352

5453
result = self._callFUT(entity_pb)
5554
self.assertTrue(isinstance(result, types.GeneratorType))
56-
self.assertEqual(list(result), [(name1, val_pb1), (name2, val_pb2)])
55+
self.assertEqual(sorted(result),
56+
sorted([(name1, val_pb1), (name2, val_pb2)]))
5757

5858

5959
class Test_entity_from_protobuf(unittest2.TestCase):

0 commit comments

Comments
 (0)