Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple datastore entities with the same ID!

I've got a huge problem - multiple entities in my datastore of the same kind have the same id! Their keys are Keys, 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.

  1. Is this normal?
  2. Is there any way to get a unique numeric identifier automatically generated? I understand that I could supply my own id values, but having to implement my own system for this seems extreme!
like image 803
Riley Lark Avatar asked Nov 19 '10 03:11

Riley Lark


2 Answers

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.

like image 98
David Underhill Avatar answered Dec 16 '22 00:12

David Underhill


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.

like image 28
Robert Kluin Avatar answered Dec 15 '22 22:12

Robert Kluin