diff --git a/mongoengine/connection.py b/mongoengine/connection.py index 31f4cbcc..0aa040ed 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -8,8 +8,9 @@ __all__ = ['ConnectionError', 'connect', 'register_connection', DEFAULT_CONNECTION_NAME = 'default' if pymongo.version_tuple[0] >= 3: - READ_PREFERENCE = ReadPreference.SECONDARY_PREFERRED + READ_PREFERENCE = ReadPreference.PRIMARY else: + from pymongo import MongoReplicaSetClient READ_PREFERENCE = False @@ -126,6 +127,8 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False): if conn_settings == connection_settings and _connections.get(db_alias, None): connection = _connections[db_alias] break + if pymongo.version_tuple[0] < 3: + connection_class = MongoReplicaSetClient _connections[alias] = connection if connection else connection_class(**conn_settings) except Exception, e: diff --git a/mongoengine/document.py b/mongoengine/document.py index c9304c2b..b27bd086 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -295,10 +295,10 @@ class Document(BaseDocument): # I think the self._created flag is not necessarily required in PyMongo3 # but may cause test test_collection_name_and_primary to fail - if pymongo.version_tuple[0] < 3: - created = ('_id' not in doc or self._created or force_insert) - else: - created = ('_id' not in doc or force_insert) + # if pymongo.version_tuple[0] < 3: + created = ('_id' not in doc or self._created or force_insert) + # else: + # created = ('_id' not in doc or force_insert) signals.pre_save_post_validation.send(self.__class__, document=self, created=created) diff --git a/mongoengine/queryset/base.py b/mongoengine/queryset/base.py index 11c92ece..09a4c3bc 100644 --- a/mongoengine/queryset/base.py +++ b/mongoengine/queryset/base.py @@ -424,8 +424,6 @@ class BaseQuerySet(object): if call_document_delete: cnt = 0 for doc in queryset: - # How the fuck did this worked before ??? - # doc.delete(write_concern=write_concern) doc.delete(**write_concern) cnt += 1 return cnt diff --git a/tests/document/indexes.py b/tests/document/indexes.py index b1ea3707..b8b3ba0c 100644 --- a/tests/document/indexes.py +++ b/tests/document/indexes.py @@ -509,12 +509,12 @@ class IndexesTest(unittest.TestCase): self.assertEqual(BlogPost.objects.count(), 10) self.assertEqual(BlogPost.objects.hint().count(), 10) - # here we seem to have find a bug in PyMongo 3. - # The cursor first makes a SON out of the list of tuples - # Then later reuses it and wonders why is it not a list of tuples - self.assertEqual(BlogPost.objects.hint([('tags', 1)]).count(), 10) - self.assertEqual(BlogPost.objects.hint([('ZZ', 1)]).count(), 10) + # PyMongo 3.0 bug + if pymongo.version != '3.0': + self.assertEqual(BlogPost.objects.hint([('tags', 1)]).count(), 10) + + self.assertEqual(BlogPost.objects.hint([('ZZ', 1)]).count(), 10) if pymongo.version >= '2.8': self.assertEqual(BlogPost.objects.hint('tags').count(), 10)