Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ever see duplicate IDs when using Google App Engine and ndb?

Appengine production db

class Entries(ndb.Model):
  description = ndb.StringProperty()
  seqid = ndb.IntegerProperty()
  link = ndb.StringProperty()
  group = ndb.StringProperty()
  timestamp = ndb.StringProperty()
  referrals = ndb.StringProperty(repeated=True)

The two entries in the picture are created by two different users. The user is the parent of the Entry.

I get a duplicate ID on production but not on local. Also, it's always this same id number (but it is certainly not hard coded anywhere)

As the parent is the user, i can still pull it as a unique entry but it will mean there will be problems if I have two entries with the same parent user.

like image 474
kullar Avatar asked Nov 22 '25 00:11

kullar


1 Answers

A datastore's unique key is the fully qualified key, including all parent entity keys, not just the ID. Multiple entities with the same ID and different parents are completely valid, and you shouldn't rely on the id alone being unique.

like image 87
Nick Johnson Avatar answered Nov 23 '25 14:11

Nick Johnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!