Do not update newly created model properties
authorSverre Rabbelier <srabbelier@gmail.com>
Thu, 26 Feb 2009 16:51:35 +0000
changeset 1516 8df06dc877aa
parent 1515 75de65fcb017
child 1517 a467d13e34ea
Do not update newly created model properties There is no real reason to favor old behavior over the current, plus the new behavior saves an extra disk write (which are expensive). Patch by: Sverre Rabbelier
app/soc/logic/models/base.py
--- a/app/soc/logic/models/base.py	Thu Feb 26 16:50:59 2009 +0000
+++ b/app/soc/logic/models/base.py	Thu Feb 26 16:51:35 2009 +0000
@@ -384,12 +384,10 @@
     if create_entity:
       # entity did not exist, so create one in a transaction
       entity = self._model.get_or_insert(key_name, **properties)
-
-
-    # there is no way to be sure if get_or_insert() returned a new entity or
-    # got an existing one due to a race, so update with properties anyway,
-    # in a transaction
-    entity = self.updateEntityProperties(entity, properties, silent=True)
+    else:
+      # If someone else already created the entity (due to a race), we
+      # should not update the propties (as they 'won' the race).
+      entity = self.updateEntityProperties(entity, properties, silent=True)
 
     if create_entity:
       # a new entity has been created call _onCreate