Skip to content

Commit 220513a

Browse files
author
erdenezul
authored
Merge pull request #1959 from bagerard/fix_write_concern_default_param
Fix but with save(write_concern=None) - introduced in 0.16.1
2 parents 3627969 + fcbabbe commit 220513a

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

docs/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Development
66
===========
77
- (Fill this out as you fix issues and develop your features).
88

9+
=================
10+
Changes in 0.16.2
11+
=================
12+
- Fix .save() that fails when called with write_concern=None (regression of 0.16.1) #1958
13+
914
=================
1015
Changes in 0.16.1
1116
=================

mongoengine/document.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def modify(self, query=None, **update):
299299
return True
300300

301301
def save(self, force_insert=False, validate=True, clean=True,
302-
write_concern={'w': 1}, cascade=None, cascade_kwargs=None,
302+
write_concern=None, cascade=None, cascade_kwargs=None,
303303
_refs=None, save_condition=None, signal_kwargs=None, **kwargs):
304304
"""Save the :class:`~mongoengine.Document` to the database. If the
305305
document already exists, it will be updated, otherwise it will be
@@ -361,6 +361,9 @@ def save(self, force_insert=False, validate=True, clean=True,
361361
if validate:
362362
self.validate(clean=clean)
363363

364+
if write_concern is None:
365+
write_concern = {'w': 1}
366+
364367
doc = self.to_mongo()
365368

366369
created = ('_id' not in doc or self._created or force_insert)

tests/queryset/queryset.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,17 @@ def test_update_write_concern(self):
400400
self.Person.drop_collection()
401401

402402
write_concern = {"fsync": True}
403-
404403
author = self.Person.objects.create(name='Test User')
405404
author.save(write_concern=write_concern)
406405

406+
# Ensure no regression of #1958
407+
author = self.Person(name='Test User2')
408+
author.save(write_concern=None) # will default to {w: 1}
409+
407410
result = self.Person.objects.update(
408411
set__name='Ross', write_concern={"w": 1})
409-
self.assertEqual(result, 1)
412+
413+
self.assertEqual(result, 2)
410414
result = self.Person.objects.update(
411415
set__name='Ross', write_concern={"w": 0})
412416
self.assertEqual(result, None)

0 commit comments

Comments
 (0)