Skip to content

Entity indexed=False not preserved in helpers.entity_from_protobuf #513

@dhermes

Description

@dhermes

In entity_from_protobuf a key is created and the values are added via

 for property_pb in pb.property: value = _get_value_from_property_pb(property_pb) entity[property_pb.name] = value

However, property_pb.value.indexed is ignored and entity has the default empty tuple for exclude_from_indexes.


To see this, first save with exclude_from_indexes non-empty and inspect the protobuf values:

>>> from gcloud import datastore >>> from gcloud.datastore.entity import Entity >>> from gcloud.datastore.key import Key >>> >>> datastore.set_default_connection() >>> datastore.set_default_dataset_id('foo') >>> >>> e = Entity(key=Key('Foo', 1), exclude_from_indexes=('foo', 'bar')) >>> e.update({ ... 'foo': 10, ... 'bar': 11, ... 'baz': 12, ... }) >>> e.save() >>> >>> entity_pb, = datastore.get_connection().lookup( ... dataset_id=e.key.dataset_id, ... key_pbs=[e.key.to_protobuf()], ... ) >>> for p in entity_pb.property: ... print p.value.indexed ... True False False

then use the key to get (which calls get_entities -> entity_from_protobuf), save the newly created (supposedly identical) Entity. After saving, check the same protobuf values:

>>> e_retrieved = e.key.get() >>> e_retrieved.save() >>> >>> entity_pb, = datastore.get_connection().lookup( ... dataset_id=e_retrieved.key.dataset_id, ... key_pbs=[e_retrieved.key.to_protobuf()], ... ) >>> for p in entity_pb.property: ... print p.value.indexed ... True True True

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the Datastore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions