File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ def entity_from_protobuf(pb):
133
133
# Check if ``value_pb`` was excluded from index. Lists need to be
134
134
# special-cased and we require all ``exclude_from_indexes`` values
135
135
# in a list agree.
136
- if is_list :
136
+ if is_list and len ( value ) > 0 :
137
137
exclude_values = set (value_pb .exclude_from_indexes
138
138
for value_pb in value_pb .array_value .values )
139
139
if len (exclude_values ) != 1 :
Original file line number Diff line number Diff line change @@ -135,6 +135,27 @@ def test_mismatched_value_indexed(self):
135
135
with self .assertRaises (ValueError ):
136
136
self ._call_fut (entity_pb )
137
137
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
+
138
159
def test_entity_no_key (self ):
139
160
from google .cloud .proto .datastore .v1 import entity_pb2
140
161
You can’t perform that action at this time.
0 commit comments