lowcoupling lowcoupling - 3 months ago 22
Python Question

Google Datastore: get_by_id with an ancestor

I am trying to retrieve an entity from a ndb Datastore
I know the id and an ancestor (not the parent!)

Although this query works fine when knowing the parent

Entity.get_by_id(int(self.request.get('entityId')),parent=entityParent.key)


The ancestor version is apparently not supported

How should I handle it?

Answer

You can't do a get for that, since that is only for exact keys and you don't have one. You need to do an ancestor query:

Entity.query(Query.id==int(self.request.get('entityId')), ancestor=ancestor.key)