[hook] entity_oldnew_value may cause bug on attributes explicitly set to None stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 09 Mar 2010 10:51:08 +0100
branchstable
changeset 4838 d4187a08ccdf
parent 4837 54969eec48eb
child 4839 f482dbdf2f8c
[hook] entity_oldnew_value may cause bug on attributes explicitly set to None
server/hook.py
--- a/server/hook.py	Tue Mar 09 10:49:57 2010 +0100
+++ b/server/hook.py	Tue Mar 09 10:51:08 2010 +0100
@@ -86,16 +86,16 @@
 
 VRegistry.REGISTRY_FACTORY['hooks'] = HooksRegistry
 
-
+_MARKER = object()
 def entity_oldnewvalue(entity, attr):
     """returns the couple (old attr value, new attr value)
     NOTE: will only work in a before_update_entity hook
     """
     # get new value and remove from local dict to force a db query to
     # fetch old value
-    newvalue = entity.pop(attr, None)
+    newvalue = entity.pop(attr, _MARKER)
     oldvalue = getattr(entity, attr)
-    if newvalue is not None:
+    if newvalue is not _MARKER:
         entity[attr] = newvalue
     return oldvalue, newvalue