I've got a huge problem - multiple entities in my datastore of the same kind have the same id! Their keys are Key
s, but I have been assuming that key.getId() will return a number that is unique among all entities of the same kind.
Not so! Different keys can return the same id! Aurgh! I can confirm this by using the data viewer - multiple entities with the same value in the id/name column. The entities with repeat keys are all in different entity groups - they have different parent keys. I have not seen any repeat ids within the same entity group, but I do not know that that cannot happen.
A key includes more than just the id or key name - it also includes the kind, parent(s), and app ID too. This is why multiple entities could potentially share the same ID portion of the key - it's perfectly fine as long as some other component of the key differs.
If you want to generate a unique id, use the db.allocate_ids
method.
The datastore identifies entities using keys (you can also see the Java docs on keys, though I believe the Python docs explain a bit more). The article on storage breakdown is a bit out-of-date, but still useful too.
The bottom line is that entities are identified by their full path in the datastore, this includes the entity's parent. So to identify the child, you will need to include the parent's id as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With