From c5ed308ea5ee408477cfa7985c8438ae5e1315da Mon Sep 17 00:00:00 2001 From: mrigal Date: Wed, 29 Apr 2015 17:12:47 +0200 Subject: [PATCH] comments update after having tested PyMongo 3.0.1 --- mongoengine/document.py | 2 +- tests/document/indexes.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mongoengine/document.py b/mongoengine/document.py index ff39b13a..838feb81 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -308,9 +308,9 @@ class Document(BaseDocument): object_id = collection.insert(doc, **write_concern) else: object_id = collection.save(doc, **write_concern) - # TODO: Pymongo 3.0 bug, fix scheduled for 3.0.1 # In PyMongo 3.0, the save() call calls internally the _update() call # but they forget to return the _id value passed back, therefore getting it back here + # Correct behaviour in 2.X and in 3.0.1+ versions if not object_id and pymongo.version_tuple == (3, 0): pk_as_mongo_obj = self._fields.get(self._meta['id_field']).to_mongo(self.pk) object_id = self._qs.filter(pk=pk_as_mongo_obj).first() and \ diff --git a/tests/document/indexes.py b/tests/document/indexes.py index f88b903a..593fe877 100644 --- a/tests/document/indexes.py +++ b/tests/document/indexes.py @@ -513,7 +513,7 @@ class IndexesTest(unittest.TestCase): self.assertEqual(BlogPost.objects.count(), 10) self.assertEqual(BlogPost.objects.hint().count(), 10) - # PyMongo 3.0 bug + # PyMongo 3.0 bug only, works correctly with 2.X and 3.0.1+ versions if pymongo.version != '3.0': self.assertEqual(BlogPost.objects.hint([('tags', 1)]).count(), 10)