From 34e28abaec58cdd412fb0d8c4409ea75b414b610 Mon Sep 17 00:00:00 2001 From: Vicens Juan Tomas Monserrat Date: Fri, 24 Nov 2023 16:01:44 +0100 Subject: [PATCH 1/7] Add mongodb 6.0 and 7.0 to the CI pipeline --- .github/workflows/github-actions.yml | 10 ++++++++++ .github/workflows/install_mongo.sh | 4 ++++ README.rst | 2 +- docs/changelog.rst | 1 + tox.ini | 4 +++- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index ce7f8a4a6..bed3ea878 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -17,6 +17,8 @@ env: MONGODB_4_0: 4.0.28 MONGODB_4_4: 4.4 MONGODB_5_0: "5.0" + MONGODB_6_0: "6.0" + MONGODB_7_0: "7.0" PYMONGO_3_4: 3.4 PYMONGO_3_6: 3.6 @@ -25,6 +27,8 @@ env: PYMONGO_3_12: 3.12 PYMONGO_4_0: 4.0 PYMONGO_4_3: 4.3.2 + PYMONGO_4_4: 4.4.1 + PYMONGO_4_6: 4.6.0 MAIN_PYTHON_VERSION: 3.7 @@ -68,6 +72,12 @@ jobs: - python-version: "3.11" MONGODB: $MONGODB_5_0 PYMONGO: $PYMONGO_4_3 + - python-version: "3.11" + MONGODB: $MONGODB_6_0 + PYMONGO: $PYMONGO_4_4 + - python-version: "3.11" + MONGODB: $MONGODB_7_0 + PYMONGO: $PYMONGO_4_6 steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/.github/workflows/install_mongo.sh b/.github/workflows/install_mongo.sh index bb7b58525..aece5f1e2 100644 --- a/.github/workflows/install_mongo.sh +++ b/.github/workflows/install_mongo.sh @@ -11,6 +11,10 @@ elif [[ "$MONGODB" == *"4.4"* ]]; then mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest elif [[ "$MONGODB" == *"5.0"* ]]; then mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest +elif [[ "$MONGODB" == *"6.0"* ]]; then + mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest +elif [[ "$MONGODB" == *"7.0"* ]]; then + mongo_build=mongodb-linux-x86_64-ubuntu2004-v${MONGODB}-latest fi wget http://fastdl.mongodb.org/linux/$mongo_build.tgz diff --git a/README.rst b/README.rst index 39497fb37..64e43b6bc 100644 --- a/README.rst +++ b/README.rst @@ -31,7 +31,7 @@ an `API reference `_. Supported MongoDB Versions ========================== -MongoEngine is currently tested against MongoDB v3.6, v4.0, v4.4 and v5.0. Future versions +MongoEngine is currently tested against MongoDB v3.6, v4.0, v4.4, v5.0, v6.0 and v7.0. Future versions should be supported as well, but aren't actively tested at the moment. Make sure to open an issue or submit a pull request if you experience any problems with a more recent MongoDB versions. diff --git a/docs/changelog.rst b/docs/changelog.rst index a11745e5a..a2ccb43ce 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,6 +8,7 @@ Development =========== - (Fill this out as you fix issues and develop your features). - Fix for uuidRepresentation not read when provided in URI #2741 +- Add tests against MongoDB 6.0 and MongoDB 7.0 in the pipeline Changes in 0.27.0 ================= diff --git a/tox.ini b/tox.ini index 553c49763..1608ebd17 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = pypy3-{mg34,mg36,mg39,mg311,mg312,mg4} +envlist = pypy3-{mg34,mg36,mg39,mg311,mg312,mg4,mg432,mg441,mg460} [testenv] commands = @@ -12,5 +12,7 @@ deps = mg312: pymongo>=3.12,<3.13 mg4: pymongo>=4.0,<4.1 mg432: pymongo>=4.3,<4.4 + mg441: pymongo>=4.4,<4.5 + mg460: pymongo>=4.6,<4.7 setenv = PYTHON_EGG_CACHE = {envdir}/python-eggs From f93271b33886ab295feff26e7fbcad16ddeb8225 Mon Sep 17 00:00:00 2001 From: Vicens Juan Tomas Monserrat Date: Fri, 24 Nov 2023 16:44:33 +0100 Subject: [PATCH 2/7] Fix test indexes for MongoDB v6.0+ --- mongoengine/mongodb_support.py | 3 +++ tests/document/test_indexes.py | 36 ++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/mongoengine/mongodb_support.py b/mongoengine/mongodb_support.py index 00b87f419..23c538d02 100644 --- a/mongoengine/mongodb_support.py +++ b/mongoengine/mongodb_support.py @@ -9,6 +9,9 @@ MONGODB_36 = (3, 6) MONGODB_42 = (4, 2) MONGODB_44 = (4, 4) +MONGODB_50 = (5, 0) +MONGODB_60 = (6, 0) +MONGODB_70 = (7, 0) def get_mongodb_version(): diff --git a/tests/document/test_indexes.py b/tests/document/test_indexes.py index f367cd0f9..ea7602514 100644 --- a/tests/document/test_indexes.py +++ b/tests/document/test_indexes.py @@ -9,6 +9,7 @@ from mongoengine.connection import get_db from mongoengine.mongodb_support import ( MONGODB_42, + MONGODB_70, get_mongodb_version, ) from mongoengine.pymongo_support import PYMONGO_VERSION @@ -466,15 +467,26 @@ class Test(Document): == "IDHACK" ) - query_plan = Test.objects(a=1).only("a").exclude("id").explain() - assert ( - query_plan.get("queryPlanner") - .get("winningPlan") - .get("inputStage") - .get("stage") - == "IXSCAN" - ) mongo_db = get_mongodb_version() + query_plan = Test.objects(a=1).only("a").exclude("id").explain() + if mongo_db < MONGODB_70: + assert ( + query_plan.get("queryPlanner") + .get("winningPlan") + .get("inputStage") + .get("stage") + == "IXSCAN" + ) + elif: + assert ( + query_plan.get("queryPlanner") + .get("winningPlan") + .get("queryPlan") + .get("inputStage") + .get("stage") + == "IXSCAN" + ) + PROJECTION_STR = "PROJECTION" if mongo_db < MONGODB_42 else "PROJECTION_COVERED" assert ( query_plan.get("queryPlanner").get("winningPlan").get("stage") @@ -536,8 +548,12 @@ class BlogPost(Document): BlogPost.objects.hint("Bad Name").count() # Invalid shape argument (missing list brackets) should fail. - with pytest.raises(ValueError): - BlogPost.objects.hint(("tags", 1)).count() + if PYMONGO_VERSION <= (4, 3): + with pytest.raises(ValueError): + BlogPost.objects.hint(("tags", 1)).count() + else: + with pytest.raises(TypeError): + BlogPost.objects.hint(("tags", 1)).count() def test_collation(self): base = {"locale": "en", "strength": 2} From 9e5e0d394c4c994e2f0143717f01e5e40fccb551 Mon Sep 17 00:00:00 2001 From: Vicens Juan Tomas Monserrat Date: Fri, 24 Nov 2023 16:46:00 +0100 Subject: [PATCH 3/7] fix typo --- tests/document/test_indexes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/document/test_indexes.py b/tests/document/test_indexes.py index ea7602514..67702d7b2 100644 --- a/tests/document/test_indexes.py +++ b/tests/document/test_indexes.py @@ -477,7 +477,7 @@ class Test(Document): .get("stage") == "IXSCAN" ) - elif: + else: assert ( query_plan.get("queryPlanner") .get("winningPlan") From 9b41316d7a9088ea192ff20760684aea363fdaaf Mon Sep 17 00:00:00 2001 From: Vicens Juan Tomas Monserrat Date: Fri, 24 Nov 2023 16:51:51 +0100 Subject: [PATCH 4/7] Fix projection in MongoDB 7.0 --- tests/document/test_indexes.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/document/test_indexes.py b/tests/document/test_indexes.py index 67702d7b2..78f3257ca 100644 --- a/tests/document/test_indexes.py +++ b/tests/document/test_indexes.py @@ -488,10 +488,16 @@ class Test(Document): ) PROJECTION_STR = "PROJECTION" if mongo_db < MONGODB_42 else "PROJECTION_COVERED" - assert ( - query_plan.get("queryPlanner").get("winningPlan").get("stage") - == PROJECTION_STR - ) + if mongo_db < MONGODB_70: + assert ( + query_plan.get("queryPlanner").get("winningPlan").get("stage") + == PROJECTION_STR + ) + else: + assert ( + query_plan.get("queryPlanner").get("winningPlan").get("queryPlan").get("stage") + == PROJECTION_STR + ) query_plan = Test.objects(a=1).explain() assert ( From f1a73029435c6a5603c255cebdbdf653f888245e Mon Sep 17 00:00:00 2001 From: Vicens Juan Tomas Monserrat Date: Fri, 24 Nov 2023 17:01:48 +0100 Subject: [PATCH 5/7] Fix asserts for test_covered_index --- tests/document/test_indexes.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/tests/document/test_indexes.py b/tests/document/test_indexes.py index 78f3257ca..8b101ce0f 100644 --- a/tests/document/test_indexes.py +++ b/tests/document/test_indexes.py @@ -500,14 +500,28 @@ class Test(Document): ) query_plan = Test.objects(a=1).explain() - assert ( - query_plan.get("queryPlanner") - .get("winningPlan") - .get("inputStage") - .get("stage") - == "IXSCAN" - ) - assert query_plan.get("queryPlanner").get("winningPlan").get("stage") == "FETCH" + if mongo_db < MONGODB_70: + assert ( + query_plan.get("queryPlanner") + .get("winningPlan") + .get("queryPlan") + .get("inputStage") + .get("stage") + == "IXSCAN" + ) + else: + assert ( + query_plan.get("queryPlanner") + .get("winningPlan") + .get("inputStage") + .get("stage") + == "IXSCAN" + ) + + if mongo_db < MONGODB_70: + assert query_plan.get("queryPlanner").get("winningPlan").get("stage") == "FETCH" + else: + assert query_plan.get("queryPlanner").get("winningPlan").get("queryPlan").get("stage") == "FETCH" def test_index_on_id(self): class BlogPost(Document): From e75b68a01741d1ef1db441efe30914ee6a0ea3e3 Mon Sep 17 00:00:00 2001 From: Vicens Juan Tomas Monserrat Date: Fri, 24 Nov 2023 17:02:34 +0100 Subject: [PATCH 6/7] fmt --- tests/document/test_indexes.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/document/test_indexes.py b/tests/document/test_indexes.py index 8b101ce0f..812d4e1d4 100644 --- a/tests/document/test_indexes.py +++ b/tests/document/test_indexes.py @@ -495,7 +495,10 @@ class Test(Document): ) else: assert ( - query_plan.get("queryPlanner").get("winningPlan").get("queryPlan").get("stage") + query_plan.get("queryPlanner") + .get("winningPlan") + .get("queryPlan") + .get("stage") == PROJECTION_STR ) @@ -519,9 +522,18 @@ class Test(Document): ) if mongo_db < MONGODB_70: - assert query_plan.get("queryPlanner").get("winningPlan").get("stage") == "FETCH" + assert ( + query_plan.get("queryPlanner").get("winningPlan").get("stage") + == "FETCH" + ) else: - assert query_plan.get("queryPlanner").get("winningPlan").get("queryPlan").get("stage") == "FETCH" + assert ( + query_plan.get("queryPlanner") + .get("winningPlan") + .get("queryPlan") + .get("stage") + == "FETCH" + ) def test_index_on_id(self): class BlogPost(Document): From bda4955145dfd4f706166029780a7850e69d9c1f Mon Sep 17 00:00:00 2001 From: Vicens Juan Tomas Monserrat Date: Fri, 24 Nov 2023 17:04:51 +0100 Subject: [PATCH 7/7] fix assert --- tests/document/test_indexes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/document/test_indexes.py b/tests/document/test_indexes.py index 812d4e1d4..8a0486412 100644 --- a/tests/document/test_indexes.py +++ b/tests/document/test_indexes.py @@ -507,7 +507,6 @@ class Test(Document): assert ( query_plan.get("queryPlanner") .get("winningPlan") - .get("queryPlan") .get("inputStage") .get("stage") == "IXSCAN" @@ -516,6 +515,7 @@ class Test(Document): assert ( query_plan.get("queryPlanner") .get("winningPlan") + .get("queryPlan") .get("inputStage") .get("stage") == "IXSCAN"