id allocated for a new entity was already in use

32 views
Skip to first unread message

siebz0r via StackOverflow

unread,
May 9, 2017, 4:33:05 AM5/9/17
to google-appengin...@googlegroups.com

I recently moved entities from a namespace to another namespace and added a parent. Since then I noticed the following error appearing:

BadRequestError: the id allocated for a new entity was already in use, please try again: app: "p~appid"
name_space: "xyz"
path <
  Element {
    type: "Challenge"
    name: "chal"
  }
  Element {
    type: "Answer"
    id: 0x14657000000000
  }
>

After some research I came to the conclusion that this happens because the id generator generates numeric ids that already exist. Since I moved the entities to another path, a different id generator is used and that generator is not aware of existing ids.

I really want to prevent this as this results in unsuccessful requests. I found numerous solutions for the older db api that involve allocating specific ids that are troublesome so the generator knows these exist. However I cannot seem to allocate a specific id for an ndb model.

I've tried to use retrying to retry putting a model but this also doesn't seem to help.

Is there any way to solve this?



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/43864764/id-allocated-for-a-new-entity-was-already-in-use

Rob Curtis via StackOverflow

unread,
May 17, 2017, 8:58:08 AM5/17/17
to google-appengin...@googlegroups.com

I haven't tested this, but I think a solution is to use allocate_ids(1, parent=) and use the new_parent_key to create the actual key that you'll be using.

id = ndb.Model.allocated_ids(size=1, parent=old_parent_key)[0]
key = ndb.Key(cls, id, parent=new_parent_key).

So old_parent_key is the parent you used previously, and you create keys with the new_parent_key(that you're now using). As far as I'm aware, allocate_ids doesn't actually fetch the entities.

see ndb id allocation



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/43864764/id-allocated-for-a-new-entity-was-already-in-use/44025484#44025484

Rob Curtis via StackOverflow

unread,
May 17, 2017, 9:53:06 AM5/17/17
to google-appengin...@googlegroups.com

I haven't tested this, but I think a solution is to use allocate_ids(1, parent=old_parent_key) and use the new_parent_key to create the actual key that you'll be using.

Reply all
Reply to author
Forward
0 new messages