I have a collection of entities with both parent keys and string ids. Sometimes I need to change the string id (update the entity with a new id). From this question (Modify a Google App Engine entity id?), it looks like I need to create a new entity and delete the old one.
Of course, I want to preserve all of the properties in the old entity when creating the new one, but there doesn't seem to be a clone
method for NDB entities.
Is this the best way to change an entity's id, while preserving the parent?
# clone the old_entity and parent as new_entity
new_entity = MyModel(**old_entity.to_dict(), id=new_id, parent=old_entity.parent())
And then, I should be able to do this to replace the old entity with the new one:
new_entity.put() # save the new entity
old_entity.key.delete() # delete the old entity