Skip to content

Commit 61e3c2c

Browse files
committed
Add support for 'list_value' field of a Value protobuf.
Fixes #223. Manually lands Tagtoo/gcloud-python@0475d5e, included by mistake in PR #126.
1 parent 0a2cd13 commit 61e3c2c

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

gcloud/datastore/_helpers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def _get_value_from_value_pb(value_pb):
112112
elif value_pb.HasField('entity_value'):
113113
return Entity.from_protobuf(value_pb.entity_value)
114114

115+
elif value_pb.list_value:
116+
return [_get_value_from_value_pb(x) for x in value_pb.list_value]
117+
115118
else:
116119
return None
117120

gcloud/datastore/test__helpers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ def test_entity(self):
166166
self.assertTrue(isinstance(entity, Entity))
167167
self.assertEqual(entity['foo'], 'Foo')
168168

169+
def test_list(self):
170+
from gcloud.datastore.datastore_v1_pb2 import Value
171+
172+
pb = Value()
173+
list_pb = pb.list_value
174+
item_pb = list_pb.add()
175+
item_pb.string_value = 'Foo'
176+
item_pb = list_pb.add()
177+
item_pb.string_value = 'Bar'
178+
items = self._callFUT(pb)
179+
self.assertEqual(items, ['Foo', 'Bar'])
180+
169181
def test_unknown(self):
170182
from gcloud.datastore.datastore_v1_pb2 import Value
171183

0 commit comments

Comments
 (0)