Suppose I have create a new entity as follows:
item = Item()
item.property = property_value
item_key1 = item.put()
Question 1: In the same file immediately after this line, what happens if I do the following:
item_key2 = item.put()
Now, does datastore have one entity - item, or do datastore have two entities identified by item_key1 and item_key2, respectively?
Question 2: In the same file immediately after this line (without the code added in Question 1), what happens if I do the following:
item.property = new_property_value
item.put()
Does the same entity in datastore get updated, or does datastore create a new entity with property equals to new_property_value?
A follow up question to Question 2: If datastore creates two entities in this case, does it mean I have to do the following to update an entity, even if the entity was just created in the same function?
item = Item()
item.property = property_value
# entity written to datastore
item_key = item.put()
# get the entity from the datastore to make sure it is the entity to update
item = item_key.get()
# update the value
item.property = new_property_value
# put it back to datastore
item.put()
This looks very silly, and cost twice as much in datastore write.
Thanks.