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:
|
if value:
|
||||||
continue
|
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
|
default = None
|
||||||
|
|
||||||
if path in self._fields:
|
if path in self._fields:
|
||||||
@ -789,8 +789,8 @@ class BaseDocument(object):
|
|||||||
if default is not None:
|
if default is not None:
|
||||||
if callable(default):
|
if callable(default):
|
||||||
default = default()
|
default = default()
|
||||||
if default != value:
|
if default != value:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
del(set_data[path])
|
del(set_data[path])
|
||||||
unset_data[path] = 1
|
unset_data[path] = 1
|
||||||
|
@ -1048,6 +1048,26 @@ class DocumentTest(unittest.TestCase):
|
|||||||
except ValidationError:
|
except ValidationError:
|
||||||
self.fail()
|
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):
|
def test_save_max_recursion_not_hit(self):
|
||||||
|
|
||||||
class Person(Document):
|
class Person(Document):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user