Skip to content

Commit 27aa15c

Browse files
committed
first adaptations after comments and find-outs
1 parent e5daf8c commit 27aa15c

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

mongoengine/connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
DEFAULT_CONNECTION_NAME = 'default'
1010
if pymongo.version_tuple[0] >= 3:
11-
READ_PREFERENCE = ReadPreference.SECONDARY_PREFERRED
11+
READ_PREFERENCE = ReadPreference.PRIMARY
1212
else:
13+
from pymongo import MongoReplicaSetClient
1314
READ_PREFERENCE = False
1415

1516

@@ -123,6 +124,8 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False):
123124
if conn_settings == connection_settings and _connections.get(db_alias, None):
124125
connection = _connections[db_alias]
125126
break
127+
if pymongo.version_tuple[0] < 3:
128+
connection_class = MongoReplicaSetClient
126129

127130
_connections[alias] = connection if connection else connection_class(**conn_settings)
128131
except Exception, e:

mongoengine/document.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ def save(self, force_insert=False, validate=True, clean=True,
290290

291291
# I think the self._created flag is not necessarily required in PyMongo3
292292
# but may cause test test_collection_name_and_primary to fail
293-
if pymongo.version_tuple[0] < 3:
294-
created = ('_id' not in doc or self._created or force_insert)
295-
else:
296-
created = ('_id' not in doc or force_insert)
293+
# if pymongo.version_tuple[0] < 3:
294+
created = ('_id' not in doc or self._created or force_insert)
295+
# else:
296+
# created = ('_id' not in doc or force_insert)
297297

298298
signals.pre_save_post_validation.send(self.__class__, document=self,
299299
created=created)

mongoengine/queryset/base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,6 @@ def delete(self, write_concern=None, _from_doc_delete=False):
424424
if call_document_delete:
425425
cnt = 0
426426
for doc in queryset:
427-
# How the fuck did this worked before ???
428-
# doc.delete(write_concern=write_concern)
429427
doc.delete(**write_concern)
430428
cnt += 1
431429
return cnt

tests/document/indexes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,12 @@ class BlogPost(Document):
509509

510510
self.assertEqual(BlogPost.objects.count(), 10)
511511
self.assertEqual(BlogPost.objects.hint().count(), 10)
512-
# here we seem to have find a bug in PyMongo 3.
513-
# The cursor first makes a SON out of the list of tuples
514-
# Then later reuses it and wonders why is it not a list of tuples
515-
self.assertEqual(BlogPost.objects.hint([('tags', 1)]).count(), 10)
516512

517-
self.assertEqual(BlogPost.objects.hint([('ZZ', 1)]).count(), 10)
513+
# PyMongo 3.0 bug
514+
if pymongo.version != '3.0':
515+
self.assertEqual(BlogPost.objects.hint([('tags', 1)]).count(), 10)
516+
517+
self.assertEqual(BlogPost.objects.hint([('ZZ', 1)]).count(), 10)
518518

519519
if pymongo.version >= '2.8':
520520
self.assertEqual(BlogPost.objects.hint('tags').count(), 10)

0 commit comments

Comments
 (0)