Fixing bug setting a value that equates to false
This commit is contained in:
parent
72aa191e70
commit
ac72722e57
@ -762,7 +762,7 @@ class BaseDocument(object):
|
||||
if value:
|
||||
continue
|
||||
|
||||
# If we've set a value that ain't the default value unset it.
|
||||
# If we've set a value that ain't the default value dont unset it.
|
||||
default = None
|
||||
|
||||
if path in self._fields:
|
||||
@ -789,8 +789,8 @@ class BaseDocument(object):
|
||||
if default is not None:
|
||||
if callable(default):
|
||||
default = default()
|
||||
if default != value:
|
||||
continue
|
||||
if default != value:
|
||||
continue
|
||||
|
||||
del(set_data[path])
|
||||
unset_data[path] = 1
|
||||
|
@ -1048,6 +1048,26 @@ class DocumentTest(unittest.TestCase):
|
||||
except ValidationError:
|
||||
self.fail()
|
||||
|
||||
def test_save_to_a_value_that_equates_to_false(self):
|
||||
|
||||
class Thing(EmbeddedDocument):
|
||||
count = IntField()
|
||||
|
||||
class User(Document):
|
||||
thing = EmbeddedDocumentField(Thing)
|
||||
|
||||
User.drop_collection()
|
||||
|
||||
user = User(thing=Thing(count=1))
|
||||
user.save()
|
||||
user.reload()
|
||||
|
||||
user.thing.count = 0
|
||||
user.save()
|
||||
|
||||
user.reload()
|
||||
self.assertEquals(user.thing.count, 0)
|
||||
|
||||
def test_save_max_recursion_not_hit(self):
|
||||
|
||||
class Person(Document):
|
||||
|
Loading…
x
Reference in New Issue
Block a user