From 7e980a16d088d6b73f7e3e6b4bdb3e5b75bd759b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristinn=20O=CC=88rn=20Sigur=C3=B0sson?= Date: Fri, 5 Apr 2013 11:01:46 +0200 Subject: [PATCH] Don't run unset on IntField if the value is 0 (zero). The IntField in unset if the IntField value doesn't validate to "truthify" (therefore, is set as 0) and the default value of the IntField in question is 0. This is not a logical functionality in my opinion. Take this example. You have an IntField that is a counter which can be incremented and decremented. This counter has the default value of 0 and is a required field. Every time the counter reaches 0, the field is unset. --- mongoengine/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoengine/base.py b/mongoengine/base.py index 42091568..fa6f825f 100644 --- a/mongoengine/base.py +++ b/mongoengine/base.py @@ -1207,7 +1207,7 @@ class BaseDocument(object): # Determine if any changed items were actually unset. for path, value in set_data.items(): - if value or type(value) in [bool, int]: + if value or isinstance(value, (bool, int)): continue # If we've set a value that ain't the default value dont unset it.