Skip to content

Commit efa90d8

Browse files
author
Luke Sneeringer
committed
Non-functional datastore fix for #3152.
1 parent 26214d2 commit efa90d8

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

datastore/google/cloud/datastore/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def entity_from_protobuf(pb):
133133
# Check if ``value_pb`` was excluded from index. Lists need to be
134134
# special-cased and we require all ``exclude_from_indexes`` values
135135
# in a list agree.
136-
if is_list:
136+
if is_list and len(value) > 0:
137137
exclude_values = set(value_pb.exclude_from_indexes
138138
for value_pb in value_pb.array_value.values)
139139
if len(exclude_values) != 1:

datastore/tests/unit/test_helpers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,27 @@ def test_mismatched_value_indexed(self):
135135
with self.assertRaises(ValueError):
136136
self._call_fut(entity_pb)
137137

138+
def test_index_mismatch_ignores_empty_list(self):
139+
from google.cloud.proto.datastore.v1 import entity_pb2
140+
from google.cloud.datastore.helpers import _new_value_pb
141+
142+
_PROJECT = 'PROJECT'
143+
_KIND = 'KIND'
144+
_ID = 1234
145+
entity_pb = entity_pb2.Entity()
146+
entity_pb.key.partition_id.project_id = _PROJECT
147+
entity_pb.key.path.add(kind=_KIND, id=_ID)
148+
149+
array_val_pb = _new_value_pb(entity_pb, 'baz')
150+
array_pb = array_val_pb.array_value.values
151+
152+
# unindexed_value_pb1 = array_pb.add()
153+
# unindexed_value_pb1.integer_value = 10
154+
155+
entity = self._call_fut(entity_pb)
156+
entity_dict = dict(entity)
157+
self.assertIsInstance(entity_dict['baz'], list)
158+
138159
def test_entity_no_key(self):
139160
from google.cloud.proto.datastore.v1 import entity_pb2
140161

0 commit comments

Comments
 (0)