From 97c99ca40daf4fb4225d008c8b01fa3bfc002459 Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Tue, 23 Feb 2021 21:49:45 +0100 Subject: [PATCH 1/2] Add test case for #2473 --- tests/queryset/test_queryset_aggregation.py | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/queryset/test_queryset_aggregation.py b/tests/queryset/test_queryset_aggregation.py index a9c042de..ecc0db6e 100644 --- a/tests/queryset/test_queryset_aggregation.py +++ b/tests/queryset/test_queryset_aggregation.py @@ -248,6 +248,34 @@ class TestQuerysetAggregate(MongoDBTestCase): assert list(data) == [{"_id": p1.pk, "name": "ISABELLA LUANNA"}] + def test_queryset_aggregation_geonear_aggregation_on_pointfield(self): + """test ensures that $geonear can be used as a 1-stage pipeline and that + MongoEngine does not interfer with such pipeline (#2473) + """ + + class Aggr(Document): + name = StringField() + c = PointField() + + Aggr.drop_collection() + + agg1 = Aggr(name="X", c=[10.634584, 35.8245029]).save() + agg2 = Aggr(name="Y", c=[10.634584, 35.8245029]).save() + + pipeline = [ + { + "$geoNear": { + "near": {"type": "Point", "coordinates": [10.634584, 35.8245029]}, + "distanceField": "c", + "spherical": True, + } + } + ] + assert list(Aggr.objects.aggregate(*pipeline)) == [ + {"_id": agg1.id, "c": 0.0, "name": "X"}, + {"_id": agg2.id, "c": 0.0, "name": "Y"}, + ] + if __name__ == "__main__": unittest.main() From 1f220b4eaf8bc2e834a3c7e1fbfa4909d237e7cf Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Tue, 23 Feb 2021 21:51:41 +0100 Subject: [PATCH 2/2] update changelog and fix minor typo in docstring --- docs/changelog.rst | 1 + mongoengine/fields.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index b904a2b8..5898eb1f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,6 +6,7 @@ Changelog Development =========== - (Fill this out as you fix issues and develop your features). +- Bugfix: manually setting SequenceField in DynamicDocument doesn't increment the counter #2471 Changes in 0.22.1 ================= diff --git a/mongoengine/fields.py b/mongoengine/fields.py index c20333a8..10bba54b 100644 --- a/mongoengine/fields.py +++ b/mongoengine/fields.py @@ -1162,7 +1162,7 @@ class ReferenceField(BaseField): :param document_type: The type of Document that will be referenced :param dbref: Store the reference as :class:`~pymongo.dbref.DBRef` - or as the :class:`~pymongo.objectid.ObjectId`.id . + or as the :class:`~pymongo.objectid.ObjectId`. :param reverse_delete_rule: Determines what to do when the referring object is deleted :param kwargs: Keyword arguments passed into the parent :class:`~mongoengine.BaseField`