From d96fcdb35cfcf083997c07a8f92afa022abf95df Mon Sep 17 00:00:00 2001 From: Matthieu Rigal Date: Sun, 21 Jun 2015 03:24:05 +0200 Subject: [PATCH] Fixed problem of ordering when using near_sphere operator --- mongoengine/queryset/transform.py | 3 ++- tests/queryset/geo.py | 7 ------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/mongoengine/queryset/transform.py b/mongoengine/queryset/transform.py index 91915703..7ede8212 100644 --- a/mongoengine/queryset/transform.py +++ b/mongoengine/queryset/transform.py @@ -128,7 +128,8 @@ def query(_doc_cls=None, _field_operation=False, **query): mongo_query[key].update(value) # $max/minDistance needs to come last - convert to SON value_dict = mongo_query[key] - if ('$maxDistance' in value_dict or '$minDistance' in value_dict) and '$near' in value_dict: + if ('$maxDistance' in value_dict or '$minDistance' in value_dict) and \ + ('$near' in value_dict or '$nearSphere' in value_dict): value_son = SON() for k, v in value_dict.iteritems(): if k == '$maxDistance' or k == '$minDistance': diff --git a/tests/queryset/geo.py b/tests/queryset/geo.py index 889dac38..4a800114 100644 --- a/tests/queryset/geo.py +++ b/tests/queryset/geo.py @@ -182,13 +182,6 @@ class GeoQueriesTest(unittest.TestCase): points = Point.objects(location__near_sphere=[-122, 37.5], location__max_distance=60 / earth_radius) - # This test is sometimes failing with Mongo internals non-sense. - # See https://travis-ci.org/MongoEngine/mongoengine/builds/58729101 - try: - points.count() - except OperationFailure: - raise SkipTest("Sometimes MongoDB ignores its capacities on maxDistance") - self.assertEqual(points.count(), 2) # Test query works with max_distance being farer from one point