Skip to content

Storing an Entity as an indexed property value always fails #529

Description

@dhermes

From the spec:

If a value is itself an entity, it cannot have indexed set to true.

This means when the entity_value is added we should set indexed to False on the property. (This is currently not easy, see #403, #404 and #512.)

Or maybe we should just document that users need to add a property name to exclude_from_indexes if that property is an Entity.


To replicate:

>>>importos>>>fromgcloudimportdatastore>>>fromgcloud.datastore.entityimportEntity>>>fromgcloud.datastore.keyimportKey>>>>>>datastore.set_default_connection()
>>>dataset_id=os.getenv('GCLOUD_TESTS_DATASET_ID')
>>>datastore.set_default_dataset_id(dataset_id)
>>>>>>e=Entity(key=Key('Foo', 1))
>>>e2=Entity(key=Key('Foo', 2))
>>>e['bar'] =e2>>>e.save()
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"gcloud/datastore/entity.py", line144, insaveexclude_from_indexes=self.exclude_from_indexes)
File"gcloud/datastore/connection.py", line495, insave_entityresult=self.commit(dataset_id, mutation)
File"gcloud/datastore/connection.py", line376, incommitdatastore_pb.CommitResponse)
File"gcloud/datastore/connection.py", line100, in_rpcdata=request_pb.SerializeToString())
File"gcloud/datastore/connection.py", line77, in_requestraisesix.moves.http_client.HTTPException(message)
httplib.HTTPException: Requestfailedwithstatuscode400.Errorwas: Entityvalueisindexed.

and notice it doesn't fail if the property is correctly unindexed:

>>>e=Entity(key=Key('Foo', 1), exclude_from_indexes=('bar',))
>>>e['bar'] =e2>>>e.save()
>>>e.key.delete()

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the Datastore API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions