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
In
Key.id(), the checkalso ignores
False-y objects other thanNone.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?/cc @pcostell