first adaptations after comments and find-outs

This commit is contained in:
mrigal 2015-04-09 10:57:19 +02:00 committed by Matthieu Rigal
parent 46817caa68
commit ccbd128fa2
4 changed files with 13 additions and 12 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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

View File

@ -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)