Skip to content

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

Closed

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

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: datastoreIssues related to the Datastore API.
    on Jan 8, 2015
  2. self-assigned this
    on Jan 14, 2015
  3. added 3 commits that reference this issue on Jan 14, 2015
    99c1a0b
    0647c93
    3e7ade7
  4. modified the milestone: on Jan 30, 2015
  5. added a commit that references this issue on Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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