Skip to content

Commit 7941016

Browse files
committed
removed wire_concern usage and cosmetics
1 parent f97db93 commit 7941016

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

mongoengine/queryset/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ def snapshot(self, enabled):
940940
.. deprecated:: Ignored with PyMongo 3+
941941
"""
942942
if IS_PYMONGO_3:
943-
msg = ("snapshot is deprecated as it has no impact when using PyMongo 3+.")
943+
msg = "snapshot is deprecated as it has no impact when using PyMongo 3+."
944944
warnings.warn(msg, DeprecationWarning)
945945
queryset = self.clone()
946946
queryset._snapshot = enabled
@@ -966,7 +966,7 @@ def slave_okay(self, enabled):
966966
.. deprecated:: Ignored with PyMongo 3+
967967
"""
968968
if IS_PYMONGO_3:
969-
msg = ("slave_okay is deprecated as it has no impact when using PyMongo 3+.")
969+
msg = "slave_okay is deprecated as it has no impact when using PyMongo 3+."
970970
warnings.warn(msg, DeprecationWarning)
971971
queryset = self.clone()
972972
queryset._slave_okay = enabled

mongoengine/queryset/transform.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,15 @@ def query(_doc_cls=None, _field_operation=False, **query):
128128
mongo_query[key].update(value)
129129
# $maxDistance needs to come last - convert to SON
130130
value_dict = mongo_query[key]
131-
if ('$maxDistance' in value_dict and '$near' in value_dict):
131+
if '$maxDistance' in value_dict and '$near' in value_dict:
132132
value_son = SON()
133133
if isinstance(value_dict['$near'], dict):
134134
for k, v in value_dict.iteritems():
135135
if k == '$maxDistance':
136136
continue
137137
value_son[k] = v
138-
if (get_connection().max_wire_version <= 1):
139-
value_son['$maxDistance'] = value_dict[
140-
'$maxDistance']
141-
else:
142-
value_son['$near'] = SON(value_son['$near'])
143-
value_son['$near'][
144-
'$maxDistance'] = value_dict['$maxDistance']
138+
value_son['$near'] = SON(value_son['$near'])
139+
value_son['$near']['$maxDistance'] = value_dict['$maxDistance']
145140
else:
146141
for k, v in value_dict.iteritems():
147142
if k == '$maxDistance':

tests/queryset/queryset.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,11 @@ class Blog(Document):
708708

709709
Blog.drop_collection()
710710

711+
# get MongoDB version info
712+
connection = get_connection()
713+
info = connection.test.command('buildInfo')
714+
mongodb_version = tuple([int(i) for i in info['version'].split('.')])
715+
711716
# Recreates the collection
712717
self.assertEqual(0, Blog.objects.count())
713718

@@ -724,7 +729,7 @@ class Blog(Document):
724729
blogs.append(Blog(title="post %s" % i, posts=[post1, post2]))
725730

726731
Blog.objects.insert(blogs, load_bulk=False)
727-
if (get_connection().max_wire_version <= 1):
732+
if mongodb_version < (2, 6):
728733
self.assertEqual(q, 1)
729734
else:
730735
# profiling logs each doc now in the bulk op
@@ -737,7 +742,7 @@ class Blog(Document):
737742
self.assertEqual(q, 0)
738743

739744
Blog.objects.insert(blogs)
740-
if (get_connection().max_wire_version <= 1):
745+
if mongodb_version < (2, 6):
741746
self.assertEqual(q, 2) # 1 for insert, and 1 for in bulk fetch
742747
else:
743748
# 99 for insert, and 1 for in bulk fetch
@@ -869,8 +874,10 @@ class Project(Document):
869874

870875
self.assertEqual(q, 3)
871876

877+
@skip_pymongo3
872878
def test_slave_okay(self):
873-
"""Ensures that a query can take slave_okay syntax
879+
"""Ensures that a query can take slave_okay syntax.
880+
Useless with PyMongo 3+ as well as with MongoDB 3+.
874881
"""
875882
person1 = self.Person(name="User A", age=20)
876883
person1.save()

0 commit comments

Comments
 (0)