Reputation: 2169
I am working on a web application based on Google App Engine (Python / Webapp2) and Google NDB Datastore. I assumed that if I tried to add a new entity using as parent key the key of a no longer existing entity an exception was thrown. I have instead found the entity is actually created. Am i doing something wrong?
I may check before whether the parent still exist through a keys_only query. Does it consume GAE read quotas?
Upvotes: 1
Views: 207
Reputation: 1816
As for your second question, the AppEngine pricing page says:
Calls to the datastore API result in the following billable operations. Small datastore operations include calls to allocate datastore ids or keys-only queries. These operations are free.
Complementing on @andrei's answer to the first question, no key reference in Ndb is checked for refering to an existing entity, this is true for keys used as parent, as well as for keys used as ̀KeyProperty
within an entity.
Upvotes: 0
Reputation: 41099
You can create a key for any entity whether this entity exists or not. This is because a key is simply an encoding of an entity kind and either an id or name (and ancestor keys, if any).
This means that you can store a child entity before a parent entity is saved, as long as you know the parent's id or name. You cannot reassign a child from one parent to another, though.
Upvotes: 4