Fix but with save(write_concern=None) - introduced in 0.16.1
This commit is contained in:
parent
3627969fce
commit
fcbabbe357
@ -6,6 +6,11 @@ Development
|
|||||||
===========
|
===========
|
||||||
- (Fill this out as you fix issues and develop your features).
|
- (Fill this out as you fix issues and develop your features).
|
||||||
|
|
||||||
|
=================
|
||||||
|
Changes in 0.16.2
|
||||||
|
=================
|
||||||
|
- Fix .save() that fails when called with write_concern=None (regression of 0.16.1) #1958
|
||||||
|
|
||||||
=================
|
=================
|
||||||
Changes in 0.16.1
|
Changes in 0.16.1
|
||||||
=================
|
=================
|
||||||
|
@ -299,7 +299,7 @@ class Document(six.with_metaclass(TopLevelDocumentMetaclass, BaseDocument)):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def save(self, force_insert=False, validate=True, clean=True,
|
def save(self, force_insert=False, validate=True, clean=True,
|
||||||
write_concern={'w': 1}, cascade=None, cascade_kwargs=None,
|
write_concern=None, cascade=None, cascade_kwargs=None,
|
||||||
_refs=None, save_condition=None, signal_kwargs=None, **kwargs):
|
_refs=None, save_condition=None, signal_kwargs=None, **kwargs):
|
||||||
"""Save the :class:`~mongoengine.Document` to the database. If the
|
"""Save the :class:`~mongoengine.Document` to the database. If the
|
||||||
document already exists, it will be updated, otherwise it will be
|
document already exists, it will be updated, otherwise it will be
|
||||||
@ -361,6 +361,9 @@ class Document(six.with_metaclass(TopLevelDocumentMetaclass, BaseDocument)):
|
|||||||
if validate:
|
if validate:
|
||||||
self.validate(clean=clean)
|
self.validate(clean=clean)
|
||||||
|
|
||||||
|
if write_concern is None:
|
||||||
|
write_concern = {'w': 1}
|
||||||
|
|
||||||
doc = self.to_mongo()
|
doc = self.to_mongo()
|
||||||
|
|
||||||
created = ('_id' not in doc or self._created or force_insert)
|
created = ('_id' not in doc or self._created or force_insert)
|
||||||
|
@ -400,13 +400,17 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
self.Person.drop_collection()
|
self.Person.drop_collection()
|
||||||
|
|
||||||
write_concern = {"fsync": True}
|
write_concern = {"fsync": True}
|
||||||
|
|
||||||
author = self.Person.objects.create(name='Test User')
|
author = self.Person.objects.create(name='Test User')
|
||||||
author.save(write_concern=write_concern)
|
author.save(write_concern=write_concern)
|
||||||
|
|
||||||
|
# Ensure no regression of #1958
|
||||||
|
author = self.Person(name='Test User2')
|
||||||
|
author.save(write_concern=None) # will default to {w: 1}
|
||||||
|
|
||||||
result = self.Person.objects.update(
|
result = self.Person.objects.update(
|
||||||
set__name='Ross', write_concern={"w": 1})
|
set__name='Ross', write_concern={"w": 1})
|
||||||
self.assertEqual(result, 1)
|
|
||||||
|
self.assertEqual(result, 2)
|
||||||
result = self.Person.objects.update(
|
result = self.Person.objects.update(
|
||||||
set__name='Ross', write_concern={"w": 0})
|
set__name='Ross', write_concern={"w": 0})
|
||||||
self.assertEqual(result, None)
|
self.assertEqual(result, None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user