Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix list_value indexed #399

Merged
merged 6 commits into from
Dec 7, 2014
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ def save_entity(self, dataset_id, key_pb, properties,
helpers._set_protobuf_value(prop.value, value)

if name in exclude_from_indexes:
prop.value.indexed = False
if not isinstance(value, list):
prop.value.indexed = False

for sub_value in prop.value.list_value:

This comment was marked as spam.

This comment was marked as spam.

sub_value.indexed = False

# If this is in a transaction, we should just return True. The
# transaction will handle assigning any keys as necessary.
Expand Down
14 changes: 11 additions & 3 deletions gcloud/datastore/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,9 @@ def test_save_entity_w_exclude_from_indexes(self):
'commit',
])
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
result = conn.save_entity(DATASET_ID, key_pb, {'foo': u'Foo'},
exclude_from_indexes=['foo'])
result = conn.save_entity(DATASET_ID, key_pb,
{'foo': u'Foo', 'bar': [u'bar1', u'bar2']},
exclude_from_indexes=['foo', 'bar'])
self.assertEqual(result, True)
cw = http._called_with
self.assertEqual(cw['uri'], URI)
Expand All @@ -706,10 +707,17 @@ def test_save_entity_w_exclude_from_indexes(self):
upsert = upserts[0]
self.assertEqual(upsert.key, key_pb)
props = list(upsert.property)
self.assertEqual(len(props), 1)
self.assertEqual(len(props), 2)
props.sort(key=lambda i: i.name, reverse=True)
self.assertEqual(props[0].name, 'foo')
self.assertEqual(props[0].value.string_value, u'Foo')
self.assertEqual(props[0].value.indexed, False)
self.assertEqual(props[1].name, 'bar')
self.assertEqual(props[1].value.list_value[0].string_value, 'bar1')
self.assertEqual(props[1].value.list_value[1].string_value, 'bar2')
self.assertEqual(props[1].value.HasField('indexed'), False)
self.assertEqual(props[1].value.list_value[0].indexed, False)
self.assertEqual(props[1].value.list_value[1].indexed, False)
self.assertEqual(len(mutation.delete), 0)
self.assertEqual(request.mode, rq_class.NON_TRANSACTIONAL)

Expand Down