Skip to content

Key id / name should fail if set to 0 / '' #443

Description

@dhermes

In Key.id(), the check

defid(self, id_to_set=None):
...
ifid_to_set:
clone=self._clone()

also ignores False-y objects other than None.

This means it ignores the integer 0, which would seem to be a valid ID. However, the backend actually rejects this, so maybe this bug only requires fixing the docstring?

>>>fromgcloudimportdatastore>>>cnxn=datastore.get_connection()
>>>importos>>>dataset=cnxn.dataset(os.getenv('GCLOUD_TESTS_DATASET_ID'))
>>>entity=dataset.entity('foo')
>>>entity.key()._path
[{'kind': 'foo'}]
>>>entity.key()._path[0]['id'] =0>>>entity<Entity[{'kind': 'foo', 'id': 0}] {}>>>>entity['bar'] =u'baz'>>>entity.save()
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"gcloud/datastore/entity.py", line246, insaveexclude_from_indexes=self.exclude_from_indexes())
File"gcloud/datastore/connection.py", line477, insave_entityresult=self.commit(dataset_id, mutation)
File"gcloud/datastore/connection.py", line377, incommitdatastore_pb.CommitResponse)
File"gcloud/datastore/connection.py", line95, in_rpcdata=request_pb.SerializeToString())
File"gcloud/datastore/connection.py", line73, in_requestraiseException('Request failed. Error was: %s'%content)
Exception: Requestfailed. Errorwas: Keypathidisinvalid. Mustnotbezero.

/cc @pcostell

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: datastoreIssues related to the Datastore API.triage meI really want to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions