Upserting is the only way to ensure docs are saved correctly (#306)
This commit is contained in:
parent
ebd1561682
commit
2c119dea47
@ -4,6 +4,7 @@ Changelog
|
||||
|
||||
Changes in 0.8.0
|
||||
================
|
||||
- Upserting is the only way to ensure docs are saved correctly (#306)
|
||||
- Fixed register_delete_rule inheritance issue
|
||||
- Fix cloning of sliced querysets (#303)
|
||||
- Fixed update_one write concern (#302)
|
||||
|
@ -231,7 +231,6 @@ class Document(BaseDocument):
|
||||
return not updated
|
||||
return created
|
||||
|
||||
upsert = self._created
|
||||
update_query = {}
|
||||
|
||||
if updates:
|
||||
@ -240,7 +239,7 @@ class Document(BaseDocument):
|
||||
update_query["$unset"] = removals
|
||||
if updates or removals:
|
||||
last_error = collection.update(select_dict, update_query,
|
||||
upsert=upsert, **write_concern)
|
||||
upsert=True, **write_concern)
|
||||
created = is_new_object(last_error)
|
||||
|
||||
cascade = (self._meta.get('cascade', True)
|
||||
|
@ -852,6 +852,14 @@ class InstanceTest(unittest.TestCase):
|
||||
self.assertEqual(person.name, None)
|
||||
self.assertEqual(person.age, None)
|
||||
|
||||
def test_inserts_if_you_set_the_pk(self):
|
||||
p1 = self.Person(name='p1', id=bson.ObjectId()).save()
|
||||
p2 = self.Person(name='p2')
|
||||
p2.id = bson.ObjectId()
|
||||
p2.save()
|
||||
|
||||
self.assertEqual(2, self.Person.objects.count())
|
||||
|
||||
def test_can_save_if_not_included(self):
|
||||
|
||||
class EmbeddedDoc(EmbeddedDocument):
|
||||
|
Loading…
x
Reference in New Issue
Block a user