I am trying to design my app engine datastore code and have thought of a potential issue and have not been able to find any concrete information in the documentation regarding what would happen in a given situation.
When I go to store an entity which has an ancestor, before storing it I check to make sure that its ancestor exists in one transaction and if it doesn't exist, I create the ancestor. Next I start another transaction where I store the entity, having created it with the ancestor key that was either found or created in the previous step. In testing with a single user or very few users, this is never going to be a problem as concurrent modification chances are at a minimum, however once deployed, my concern is that in the time between the first transaction (creation/retrieval of the ancestor) and the second transaction (adding an entity as a descendant of the ancestor) another user could potentially delete the ancestor.
My initial thinking was to have this all occur as one transaction but in the case where the ancestor did not exist and had to be created, an ancestor query to check if the entity I want to create exists will fail because of the snapshot isolation model of the datastore. However, I am not sure if this is correct.
Does anyone have any knowledge on the matter? If the ancestor was deleted, will the entity commit still work with a parent key that now refers to nothing? Will this recreate the parent so the future checks on it will return the same key? I would test this situation but I am unable to devise a practical way to do so.