Merge pull request #2483 from bagerard/mongodb44_ci

Add Mongodb 44 ci and fix incompat
This commit is contained in:
Bastien Gérard 2021-03-04 22:42:13 +01:00 committed by GitHub
commit 7147043d63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 64 additions and 29 deletions

View File

@ -11,9 +11,10 @@ on:
tags: tags:
- 'v[0-9]+\.[0-9]+\.[0-9]+*' - 'v[0-9]+\.[0-9]+\.[0-9]+*'
env: env:
MONGODB_3_4: 3.4.19 MONGODB_3_6: 3.6.14
MONGODB_3_6: 3.6.13 MONGODB_4_0: 4.0.23
MONGODB_4_0: 4.0.13 MONGODB_4_2: 4.2
MONGODB_4_4: 4.4
PYMONGO_3_4: 3.4 PYMONGO_3_4: 3.4
PYMONGO_3_6: 3.6 PYMONGO_3_6: 3.6
@ -47,14 +48,14 @@ jobs:
MONGODB: [$MONGODB_4_0] MONGODB: [$MONGODB_4_0]
PYMONGO: [$PYMONGO_3_11] PYMONGO: [$PYMONGO_3_11]
include: include:
- python-version: 3.7
MONGODB: $MONGODB_3_4
PYMONGO: $PYMONGO_3_6
- python-version: 3.7 - python-version: 3.7
MONGODB: $MONGODB_3_6 MONGODB: $MONGODB_3_6
PYMONGO: $PYMONGO_3_9 PYMONGO: $PYMONGO_3_9
- python-version: 3.7 - python-version: 3.7
MONGODB: $MONGODB_3_6 MONGODB: $MONGODB_4_2
PYMONGO: $PYMONGO_3_6
- python-version: 3.7
MONGODB: $MONGODB_4_4
PYMONGO: $PYMONGO_3_11 PYMONGO: $PYMONGO_3_11
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2

View File

@ -2,7 +2,17 @@
MONGODB=$1 MONGODB=$1
# Mongo > 4.0 follows different name convention for download links
mongo_build=mongodb-linux-x86_64-${MONGODB} mongo_build=mongodb-linux-x86_64-${MONGODB}
if [[ "$MONGODB" == *"4.2"* ]]; then
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
elif [[ "$MONGODB" == *"4.4"* ]]; then
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
fi
wget http://fastdl.mongodb.org/linux/$mongo_build.tgz wget http://fastdl.mongodb.org/linux/$mongo_build.tgz
tar xzf $mongo_build.tgz tar xzf $mongo_build.tgz
${PWD}/$mongo_build/bin/mongod --version
mongodb_dir=$(find ${PWD}/ -type d -name "mongodb-linux-x86_64*")
$mongodb_dir/bin/mongod --version

View File

@ -2,7 +2,8 @@
MONGODB=$1 MONGODB=$1
mongodb_dir=${PWD}/mongodb-linux-x86_64-${MONGODB} mongodb_dir=$(find ${PWD}/ -type d -name "mongodb-linux-x86_64*")
mkdir $mongodb_dir/data mkdir $mongodb_dir/data
$mongodb_dir/bin/mongod --dbpath $mongodb_dir/data --logpath $mongodb_dir/mongodb.log --fork $mongodb_dir/bin/mongod --dbpath $mongodb_dir/data --logpath $mongodb_dir/mongodb.log --fork
mongo --eval 'db.version();' # Make sure mongo is awake mongo --eval 'db.version();' # Make sure mongo is awake

View File

@ -7,6 +7,7 @@ Development
=========== ===========
- (Fill this out as you fix issues and develop your features). - (Fill this out as you fix issues and develop your features).
- Bugfix: manually setting SequenceField in DynamicDocument doesn't increment the counter #2471 - Bugfix: manually setting SequenceField in DynamicDocument doesn't increment the counter #2471
- Add MongoDB 4.2 and 4.4 to CI
Changes in 0.22.1 Changes in 0.22.1
================= =================

View File

@ -8,6 +8,8 @@ from mongoengine.connection import get_connection
# get_mongodb_version() # get_mongodb_version()
MONGODB_34 = (3, 4) MONGODB_34 = (3, 4)
MONGODB_36 = (3, 6) MONGODB_36 = (3, 6)
MONGODB_42 = (4, 2)
MONGODB_44 = (4, 4)
def get_mongodb_version(): def get_mongodb_version():

View File

@ -1355,21 +1355,18 @@ class BaseQuerySet:
MapReduceDocument = _import_class("MapReduceDocument") MapReduceDocument = _import_class("MapReduceDocument")
if not hasattr(self._collection, "map_reduce"):
raise NotImplementedError("Requires MongoDB >= 1.7.1")
map_f_scope = {} map_f_scope = {}
if isinstance(map_f, Code): if isinstance(map_f, Code):
map_f_scope = map_f.scope map_f_scope = map_f.scope
map_f = str(map_f) map_f = str(map_f)
map_f = Code(queryset._sub_js_fields(map_f), map_f_scope) map_f = Code(queryset._sub_js_fields(map_f), map_f_scope or None)
reduce_f_scope = {} reduce_f_scope = {}
if isinstance(reduce_f, Code): if isinstance(reduce_f, Code):
reduce_f_scope = reduce_f.scope reduce_f_scope = reduce_f.scope
reduce_f = str(reduce_f) reduce_f = str(reduce_f)
reduce_f_code = queryset._sub_js_fields(reduce_f) reduce_f_code = queryset._sub_js_fields(reduce_f)
reduce_f = Code(reduce_f_code, reduce_f_scope) reduce_f = Code(reduce_f_code, reduce_f_scope or None)
mr_args = {"query": queryset._query} mr_args = {"query": queryset._query}
@ -1379,7 +1376,7 @@ class BaseQuerySet:
finalize_f_scope = finalize_f.scope finalize_f_scope = finalize_f.scope
finalize_f = str(finalize_f) finalize_f = str(finalize_f)
finalize_f_code = queryset._sub_js_fields(finalize_f) finalize_f_code = queryset._sub_js_fields(finalize_f)
finalize_f = Code(finalize_f_code, finalize_f_scope) finalize_f = Code(finalize_f_code, finalize_f_scope or None)
mr_args["finalize"] = finalize_f mr_args["finalize"] = finalize_f
if scope: if scope:

View File

@ -7,6 +7,7 @@ import pytest
from mongoengine import * from mongoengine import *
from mongoengine.connection import get_db from mongoengine.connection import get_db
from mongoengine.mongodb_support import MONGODB_42, get_mongodb_version
class TestIndexes(unittest.TestCase): class TestIndexes(unittest.TestCase):
@ -452,9 +453,11 @@ class TestIndexes(unittest.TestCase):
.get("stage") .get("stage")
== "IXSCAN" == "IXSCAN"
) )
mongo_db = get_mongodb_version()
PROJECTION_STR = "PROJECTION" if mongo_db < MONGODB_42 else "PROJECTION_COVERED"
assert ( assert (
query_plan.get("queryPlanner").get("winningPlan").get("stage") query_plan.get("queryPlanner").get("winningPlan").get("stage")
== "PROJECTION" == PROJECTION_STR
) )
query_plan = Test.objects(a=1).explain() query_plan = Test.objects(a=1).explain()

View File

@ -21,7 +21,10 @@ from mongoengine.queryset import (
QuerySetManager, QuerySetManager,
queryset_manager, queryset_manager,
) )
from tests.utils import requires_mongodb_gte_44 from tests.utils import (
requires_mongodb_gte_44,
requires_mongodb_lt_42,
)
class db_ops_tracker(query_counter): class db_ops_tracker(query_counter):
@ -1490,6 +1493,7 @@ class TestQueryset(unittest.TestCase):
BlogPost.drop_collection() BlogPost.drop_collection()
@requires_mongodb_lt_42
def test_exec_js_query(self): def test_exec_js_query(self):
"""Ensure that queries are properly formed for use in exec_js.""" """Ensure that queries are properly formed for use in exec_js."""
@ -1527,6 +1531,7 @@ class TestQueryset(unittest.TestCase):
BlogPost.drop_collection() BlogPost.drop_collection()
@requires_mongodb_lt_42
def test_exec_js_field_sub(self): def test_exec_js_field_sub(self):
"""Ensure that field substitutions occur properly in exec_js functions.""" """Ensure that field substitutions occur properly in exec_js functions."""
@ -2660,6 +2665,8 @@ class TestQueryset(unittest.TestCase):
title = StringField(primary_key=True) title = StringField(primary_key=True)
tags = ListField(StringField()) tags = ListField(StringField())
BlogPost.drop_collection()
post1 = BlogPost(title="Post #1", tags=["mongodb", "mongoengine"]) post1 = BlogPost(title="Post #1", tags=["mongodb", "mongoengine"])
post2 = BlogPost(title="Post #2", tags=["django", "mongodb"]) post2 = BlogPost(title="Post #2", tags=["django", "mongodb"])
post3 = BlogPost(title="Post #3", tags=["hitchcock films"]) post3 = BlogPost(title="Post #3", tags=["hitchcock films"])
@ -2688,12 +2695,15 @@ class TestQueryset(unittest.TestCase):
} }
""" """
results = BlogPost.objects.map_reduce(map_f, reduce_f, "myresults") results = BlogPost.objects.order_by("_id").map_reduce(
map_f, reduce_f, "myresults2"
)
results = list(results) results = list(results)
assert results[0].object == post1 assert len(results) == 3
assert results[1].object == post2 assert results[0].object.id == post1.id
assert results[2].object == post3 assert results[1].object.id == post2.id
assert results[2].object.id == post3.id
BlogPost.drop_collection() BlogPost.drop_collection()
@ -2701,7 +2711,6 @@ class TestQueryset(unittest.TestCase):
""" """
Test map/reduce custom output Test map/reduce custom output
""" """
register_connection("test2", "mongoenginetest2")
class Family(Document): class Family(Document):
id = IntField(primary_key=True) id = IntField(primary_key=True)
@ -2774,6 +2783,7 @@ class TestQueryset(unittest.TestCase):
family.persons.push(person); family.persons.push(person);
family.totalAge += person.age; family.totalAge += person.age;
}); });
family.persons.sort((a, b) => (a.age > b.age))
} }
}); });
@ -2802,10 +2812,10 @@ class TestQueryset(unittest.TestCase):
"_id": 1, "_id": 1,
"value": { "value": {
"persons": [ "persons": [
{"age": 21, "name": "Wilson Jr"},
{"age": 45, "name": "Wilson Father"},
{"age": 40, "name": "Eliana Costa"},
{"age": 17, "name": "Tayza Mariana"}, {"age": 17, "name": "Tayza Mariana"},
{"age": 21, "name": "Wilson Jr"},
{"age": 40, "name": "Eliana Costa"},
{"age": 45, "name": "Wilson Father"},
], ],
"totalAge": 123, "totalAge": 123,
}, },
@ -2815,9 +2825,9 @@ class TestQueryset(unittest.TestCase):
"_id": 2, "_id": 2,
"value": { "value": {
"persons": [ "persons": [
{"age": 10, "name": "Igor Gabriel"},
{"age": 16, "name": "Isabella Luanna"}, {"age": 16, "name": "Isabella Luanna"},
{"age": 36, "name": "Sandra Mara"}, {"age": 36, "name": "Sandra Mara"},
{"age": 10, "name": "Igor Gabriel"},
], ],
"totalAge": 62, "totalAge": 62,
}, },
@ -2827,8 +2837,8 @@ class TestQueryset(unittest.TestCase):
"_id": 3, "_id": 3,
"value": { "value": {
"persons": [ "persons": [
{"age": 30, "name": "Arthur WA"},
{"age": 25, "name": "Paula Leonel"}, {"age": 25, "name": "Paula Leonel"},
{"age": 30, "name": "Arthur WA"},
], ],
"totalAge": 55, "totalAge": 55,
}, },
@ -3109,6 +3119,7 @@ class TestQueryset(unittest.TestCase):
freq = Person.objects.item_frequencies("city", normalize=True, map_reduce=True) freq = Person.objects.item_frequencies("city", normalize=True, map_reduce=True)
assert freq == {"CRB": 0.5, None: 0.5} assert freq == {"CRB": 0.5, None: 0.5}
@requires_mongodb_lt_42
def test_item_frequencies_with_null_embedded(self): def test_item_frequencies_with_null_embedded(self):
class Data(EmbeddedDocument): class Data(EmbeddedDocument):
name = StringField() name = StringField()
@ -3137,6 +3148,7 @@ class TestQueryset(unittest.TestCase):
ot = Person.objects.item_frequencies("extra.tag", map_reduce=True) ot = Person.objects.item_frequencies("extra.tag", map_reduce=True)
assert ot == {None: 1.0, "friend": 1.0} assert ot == {None: 1.0, "friend": 1.0}
@requires_mongodb_lt_42
def test_item_frequencies_with_0_values(self): def test_item_frequencies_with_0_values(self):
class Test(Document): class Test(Document):
val = IntField() val = IntField()
@ -3151,6 +3163,7 @@ class TestQueryset(unittest.TestCase):
ot = Test.objects.item_frequencies("val", map_reduce=False) ot = Test.objects.item_frequencies("val", map_reduce=False)
assert ot == {0: 1} assert ot == {0: 1}
@requires_mongodb_lt_42
def test_item_frequencies_with_False_values(self): def test_item_frequencies_with_False_values(self):
class Test(Document): class Test(Document):
val = BooleanField() val = BooleanField()
@ -3165,6 +3178,7 @@ class TestQueryset(unittest.TestCase):
ot = Test.objects.item_frequencies("val", map_reduce=False) ot = Test.objects.item_frequencies("val", map_reduce=False)
assert ot == {False: 1} assert ot == {False: 1}
@requires_mongodb_lt_42
def test_item_frequencies_normalize(self): def test_item_frequencies_normalize(self):
class Test(Document): class Test(Document):
val = IntField() val = IntField()
@ -3551,7 +3565,8 @@ class TestQueryset(unittest.TestCase):
Book.objects.create(title="The Stories", authors=[mark_twain, john_tolkien]) Book.objects.create(title="The Stories", authors=[mark_twain, john_tolkien])
authors = Book.objects.distinct("authors") authors = Book.objects.distinct("authors")
assert authors == [mark_twain, john_tolkien] authors_names = {author.name for author in authors}
assert authors_names == {mark_twain.name, john_tolkien.name}
def test_distinct_ListField_EmbeddedDocumentField_EmbeddedDocumentField(self): def test_distinct_ListField_EmbeddedDocumentField_EmbeddedDocumentField(self):
class Continent(EmbeddedDocument): class Continent(EmbeddedDocument):
@ -3588,7 +3603,8 @@ class TestQueryset(unittest.TestCase):
assert country_list == [scotland, tibet] assert country_list == [scotland, tibet]
continent_list = Book.objects.distinct("authors.country.continent") continent_list = Book.objects.distinct("authors.country.continent")
assert continent_list == [europe, asia] continent_list_names = {c.continent_name for c in continent_list}
assert continent_list_names == {europe.continent_name, asia.continent_name}
def test_distinct_ListField_ReferenceField(self): def test_distinct_ListField_ReferenceField(self):
class Bar(Document): class Bar(Document):

View File

@ -34,6 +34,10 @@ def get_as_pymongo(doc):
return doc.__class__.objects.as_pymongo().get(id=doc.id) return doc.__class__.objects.as_pymongo().get(id=doc.id)
def requires_mongodb_lt_42(func):
return _decorated_with_ver_requirement(func, (4, 2), oper=operator.lt)
def requires_mongodb_gte_44(func): def requires_mongodb_gte_44(func):
return _decorated_with_ver_requirement(func, (4, 4), oper=operator.ge) return _decorated_with_ver_requirement(func, (4, 4), oper=operator.ge)