From 1edae9d5bbd2b9317a58f1bbe08f9340ee5bbaf1 Mon Sep 17 00:00:00 2001 From: Elijah Frederickson Date: Wed, 18 Sep 2024 19:48:11 -0400 Subject: [PATCH 01/16] Update connection.py Resolve issue where _check_name moved files between pymongo 4.8.0 and 4.9 --- mongoengine/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoengine/connection.py b/mongoengine/connection.py index 42a79434e..9711b753e 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -2,7 +2,7 @@ from pymongo import MongoClient, ReadPreference, uri_parser from pymongo.common import _UUID_REPRESENTATIONS -from pymongo.database import _check_name +from pymongo.database_shared import _check_name # DriverInfo was added in PyMongo 3.7. try: From ab1e4014fc06e434ac62395a2270101233e19b45 Mon Sep 17 00:00:00 2001 From: Elijah Frederickson Date: Wed, 18 Sep 2024 19:54:37 -0400 Subject: [PATCH 02/16] Update connection.py --- mongoengine/connection.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mongoengine/connection.py b/mongoengine/connection.py index 9711b753e..c27ed8070 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -2,7 +2,10 @@ from pymongo import MongoClient, ReadPreference, uri_parser from pymongo.common import _UUID_REPRESENTATIONS -from pymongo.database_shared import _check_name +try: + from pymongo.database_shared import _check_name +except ImportError: + from pymongo.database import _check_name # DriverInfo was added in PyMongo 3.7. try: From b9472c81e5e5f25a5761393cf60bedbefae2627e Mon Sep 17 00:00:00 2001 From: Elijah Frederickson Date: Wed, 18 Sep 2024 19:56:57 -0400 Subject: [PATCH 03/16] Update github-actions.yml --- .github/workflows/github-actions.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index be0a83903..08afea3a2 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -31,6 +31,7 @@ env: PYMONGO_4_6: 4.6.2 PYMONGO_4_7: 4.7.3 PYMONGO_4_8: 4.8.0 + PYMONGO_4_9: 4.9 MAIN_PYTHON_VERSION: 3.9 @@ -88,6 +89,9 @@ jobs: - python-version: "3.11" MONGODB: $MONGODB_7_0 PYMONGO: $PYMONGO_4_8 + - python-version: "3.11" + MONGODB: $MONGODB_7_0 + PYMONGO: $PYMONGO_4_9 steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} From 3205e61a2b7dde4fb2b447cca543478ee08a8228 Mon Sep 17 00:00:00 2001 From: Elijah Frederickson Date: Wed, 18 Sep 2024 20:03:03 -0400 Subject: [PATCH 04/16] Add missing env --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index f72861ba4..f94198ba6 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = pypy3-{mg34,mg36,mg39,mg311,mg312,mg4,mg432,mg441,mg462,mg473,mg480} +envlist = pypy3-{mg34,mg36,mg39,mg311,mg312,mg4,mg432,mg441,mg462,mg473,mg480,mg49} skipsdist = True [testenv] @@ -16,5 +16,6 @@ deps = mg462: pymongo>=4.6,<4.7 mg473: pymongo>=4.7,<4.8 mg480: pymongo>=4.8,<4.9 + mg49: pymongo>=4.9,<5.0 setenv = PYTHON_EGG_CACHE = {envdir}/python-eggs From dbf7888c6ae5cef5f1e09c364863eb86310bde42 Mon Sep 17 00:00:00 2001 From: Elijah Frederickson Date: Wed, 18 Sep 2024 20:03:34 -0400 Subject: [PATCH 05/16] Formatting --- mongoengine/connection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mongoengine/connection.py b/mongoengine/connection.py index c27ed8070..2f07b83dd 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -2,6 +2,7 @@ from pymongo import MongoClient, ReadPreference, uri_parser from pymongo.common import _UUID_REPRESENTATIONS + try: from pymongo.database_shared import _check_name except ImportError: From 37762abc6f701c4a54f1868a095830ee0e8d1994 Mon Sep 17 00:00:00 2001 From: Elijah Frederickson Date: Wed, 18 Sep 2024 20:32:47 -0400 Subject: [PATCH 06/16] The WebIDE will only take you so far --- tests/queryset/test_queryset_aggregation.py | 9 +++++---- tests/test_connection.py | 7 ++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/queryset/test_queryset_aggregation.py b/tests/queryset/test_queryset_aggregation.py index f1d504c0b..ecfa0b6f3 100644 --- a/tests/queryset/test_queryset_aggregation.py +++ b/tests/queryset/test_queryset_aggregation.py @@ -19,10 +19,11 @@ class Bar(Document): bars = Bar.objects.read_preference( ReadPreference.SECONDARY_PREFERRED ).aggregate(pipeline) - assert ( - bars._CommandCursor__collection.read_preference - == ReadPreference.SECONDARY_PREFERRED - ) + if hasattr(bars, "_CommandCursor__collection"): + read_pref = bars._CommandCursor__collection.read_preference + else: # pymongo >= 4.9 + read_pref = bars._collection.read_preference + assert read_pref == ReadPreference.SECONDARY_PREFERRED def test_queryset_aggregation_framework(self): class Person(Document): diff --git a/tests/test_connection.py b/tests/test_connection.py index c88f87c93..5b47383b4 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -3,6 +3,8 @@ import uuid import pymongo +import pymongo.database +import pymongo.mongo_client import pytest from bson.tz_util import utc from pymongo import MongoClient, ReadPreference @@ -608,7 +610,10 @@ def test_connect_with_replicaset_via_kwargs(self): connection kwargs """ c = connect(replicaset="local-rs") - assert c._MongoClient__options.replica_set_name == "local-rs" + if hasattr(c, "_MongoClient__options"): + assert c._MongoClient__options.replica_set_name == "local-rs" + else: # pymongo >= 4.9 + assert c._options.replica_set_name == "local-rs" db = get_db() assert isinstance(db, pymongo.database.Database) assert db.name == "test" From f76f6eb7f696c406bb3efc2233092de5596455a2 Mon Sep 17 00:00:00 2001 From: Elijah Frederickson Date: Wed, 18 Sep 2024 21:26:27 -0400 Subject: [PATCH 07/16] isort to trigger ci --- tests/fields/test_datetime_field.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/fields/test_datetime_field.py b/tests/fields/test_datetime_field.py index ced10b1bc..e14acb444 100644 --- a/tests/fields/test_datetime_field.py +++ b/tests/fields/test_datetime_field.py @@ -2,14 +2,15 @@ import pytest +from mongoengine import * +from mongoengine import connection +from tests.utils import MongoDBTestCase, get_as_pymongo + try: import dateutil except ImportError: dateutil = None -from mongoengine import * -from mongoengine import connection -from tests.utils import MongoDBTestCase, get_as_pymongo class TestDateTimeField(MongoDBTestCase): From c149e1680b6197f4e3439d5028bb4bdb4120beed Mon Sep 17 00:00:00 2001 From: Elijah Frederickson Date: Wed, 18 Sep 2024 21:28:48 -0400 Subject: [PATCH 08/16] trigger ci --- tests/fields/test_datetime_field.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/fields/test_datetime_field.py b/tests/fields/test_datetime_field.py index e14acb444..d04f39b04 100644 --- a/tests/fields/test_datetime_field.py +++ b/tests/fields/test_datetime_field.py @@ -12,7 +12,6 @@ dateutil = None - class TestDateTimeField(MongoDBTestCase): def test_datetime_from_empty_string(self): """ From f0774b6280ed86e50692753783b73712e45223d4 Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Thu, 19 Sep 2024 09:17:08 +0200 Subject: [PATCH 09/16] update changelog and prepare 0.29.1 --- .github/workflows/github-actions.yml | 2 +- docs/changelog.rst | 5 +++++ mongoengine/__init__.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 08afea3a2..8ab674667 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -112,7 +112,7 @@ jobs: - name: Send coverage to Coveralls env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COVERALLS_SERVICE_NAME: github + COVERALLS_SERVICE_NAME: github-actions if: ${{ matrix.python-version == env.MAIN_PYTHON_VERSION }} run: coveralls diff --git a/docs/changelog.rst b/docs/changelog.rst index 505b9dff2..0f5ce0657 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,6 +8,11 @@ Development =========== - (Fill this out as you fix issues and develop your features). + +Changes in 0.29.1 +================= +- Add support for freshly released pymongo 4.9 #2849 + Changes in 0.29.0 ================= - Fix weakref in EmbeddedDocumentListField (causing brief mem leak in certain circumstances) #2827 diff --git a/mongoengine/__init__.py b/mongoengine/__init__.py index 3b2a884b6..f74e30a94 100644 --- a/mongoengine/__init__.py +++ b/mongoengine/__init__.py @@ -29,7 +29,7 @@ ) -VERSION = (0, 29, 0) +VERSION = (0, 29, 1) def get_version(): From 0eeec004ef777f61f019a2d0f066621727fc515f Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Tue, 10 Mar 2026 13:14:18 +0100 Subject: [PATCH 10/16] prepare 0.29.2 release --- .github/workflows/github-actions.yml | 2 +- docs/changelog.rst | 4 ++++ mongoengine/__init__.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 8ab674667..bcf9afd5e 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -54,7 +54,7 @@ jobs: test: # Test suite run against recent python versions # and against a few combination of MongoDB and pymongo - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: diff --git a/docs/changelog.rst b/docs/changelog.rst index 0f5ce0657..b360fcbea 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -9,6 +9,10 @@ Development - (Fill this out as you fix issues and develop your features). +Changes in 0.29.2 +================= +- Remove mentions of mongoengine[dot]org has we no longer own it #2905 + Changes in 0.29.1 ================= - Add support for freshly released pymongo 4.9 #2849 diff --git a/mongoengine/__init__.py b/mongoengine/__init__.py index f74e30a94..978eebc5e 100644 --- a/mongoengine/__init__.py +++ b/mongoengine/__init__.py @@ -29,7 +29,7 @@ ) -VERSION = (0, 29, 1) +VERSION = (0, 29, 2) def get_version(): From 19553b880a062c2327642fb771eaf6d097174e6e Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Tue, 10 Mar 2026 13:46:41 +0100 Subject: [PATCH 11/16] use ubuntu 22.04 for test --- .github/workflows/github-actions.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index bcf9afd5e..6c61685a3 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -54,17 +54,14 @@ jobs: test: # Test suite run against recent python versions # and against a few combination of MongoDB and pymongo - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: - python-version: [3.7, 3.8, 3.9, "3.10", 3.11, pypy3.9, pypy3.10] + python-version: [3.8, 3.9, "3.10", 3.11, pypy3.9, pypy3.10] MONGODB: [$MONGODB_4_0] PYMONGO: [$PYMONGO_3_11] include: - - python-version: 3.7 - MONGODB: $MONGODB_3_6 - PYMONGO: $PYMONGO_3_9 - python-version: 3.8 MONGODB: $MONGODB_4_4 PYMONGO: $PYMONGO_3_11 From 1fcbad8e8395eef31a4a08b4e16540ca8dbaa534 Mon Sep 17 00:00:00 2001 From: "Terence D. Honles" Date: Wed, 28 May 2025 08:48:22 +0200 Subject: [PATCH 12/16] fix CI --- .github/workflows/github-actions.yml | 20 +++--- .github/workflows/install_mongo.sh | 96 ++++++++++++++++++++++------ .github/workflows/start_mongo.sh | 23 +++++-- README.rst | 8 +-- 4 files changed, 107 insertions(+), 40 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 6c61685a3..0c14c6536 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -13,12 +13,11 @@ on: tags: - 'v[0-9]+\.[0-9]+\.[0-9]+*' env: - MONGODB_3_6: 3.6.23 - 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" + MONGODB_4_4: "4.4.29" + MONGODB_5_0: "5.0.31" + MONGODB_6_0: "6.0.22" + MONGODB_7_0: "7.0.19" + MONGODB_8_0: "8.0.9" PYMONGO_3_4: 3.4 PYMONGO_3_6: 3.6 @@ -58,11 +57,11 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8, 3.9, "3.10", 3.11, pypy3.9, pypy3.10] - MONGODB: [$MONGODB_4_0] - PYMONGO: [$PYMONGO_3_11] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.9", "pypy3.10"] + MONGODB: [$MONGODB_4_4] + PYMONGO: [$PYMONGO_3_12] include: - - python-version: 3.8 + - python-version: "3.9" MONGODB: $MONGODB_4_4 PYMONGO: $PYMONGO_3_11 - python-version: 3.9 @@ -99,7 +98,6 @@ jobs: - name: install mongo and ci dependencies run: | bash .github/workflows/install_mongo.sh ${{ matrix.MONGODB }} - bash .github/workflows/install_mongosh.sh ${{ matrix.MONGODB }} ${{ env.MONGOSH }} bash .github/workflows/install_ci_python_dep.sh bash .github/workflows/start_mongo.sh ${{ matrix.MONGODB }} - name: tox dry-run (to pre-install venv) diff --git a/.github/workflows/install_mongo.sh b/.github/workflows/install_mongo.sh index aece5f1e2..8b0798db5 100644 --- a/.github/workflows/install_mongo.sh +++ b/.github/workflows/install_mongo.sh @@ -1,24 +1,82 @@ #!/bin/bash -MONGODB=$1 - -# Mongo > 4.0 follows different name convention for download links -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 -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 +set -e # Exit immediately if a command exits with a non-zero status +set -u # Treat unset variables as an error + +if [ "$#" -ne 1 ]; then + echo >&2 "Usage: $0 " + echo >&2 "Example: $0 8.0.5" + exit 1 fi -wget http://fastdl.mongodb.org/linux/$mongo_build.tgz -tar xzf $mongo_build.tgz +MONGODB="$1" +MONGOSH=2.5.1 + +# Determine build name based on version +if [[ "$MONGODB" =~ ^(6.0|7.0|8.0) ]]; then + mongodb_build="mongodb-linux-x86_64-ubuntu2204-${MONGODB}" +elif [[ "$MONGODB" =~ ^(4.4|5.0) ]]; then + mongodb_build="mongodb-linux-x86_64-ubuntu2004-${MONGODB}" +else + echo >&2 "Error: Unsupported MongoDB version: ${MONGODB}" + usage +fi + +mongodb_tarball="${mongodb_build}.tgz" +mongodb_download_url="http://fastdl.mongodb.org/linux/${mongodb_tarball}" + +mongosh_build="mongosh-${MONGOSH}-linux-x64" +mongosh_tarball="${mongosh_build}.tgz" +mongosh_download_url="https://github.com/mongodb-js/mongosh/releases/download/v${MONGOSH}/${mongosh_tarball}" + +set -- \ + MongoDB "$mongodb_tarball" "$mongodb_download_url" \ + "MongoDB Shell" "$mongosh_tarball" "$mongosh_download_url" + +while (( $# > 0 )) ; do + name="$1" + tarball="$2" + download_url="$3" + shift 3 + + echo >&2 "Downloading ${name} from ${download_url}..." + if ! wget --quiet "$download_url"; then + echo >&2 "Error: Failed to download ${name}." + exit 1 + fi + + echo >&2 "Extracting ${tarball}..." + if ! tar xzf "${tarball}"; then + echo >&2 "Error: Failed to extract ${tarball}" + exit 1 + fi +done + +mongodb_dir=$(find "${PWD}/" -type d -name "mongodb-linux-x86_64*" -print -quit) +if [ -z "$mongodb_dir" ]; then + echo >&2 "Error: Could not find MongoDB directory after extraction." + exit 1 +fi + +mongosh_dir=$(find "${PWD}/" -type d -name "$mongosh_build" -print -quit) +if [ ! -d "$mongosh_dir" ]; then + echo >&2 "Failed to find extracted mongosh directory." + rm -f "$TARBALL" + exit 1 +fi + +echo >&2 "Creating mongo.path" +echo "export PATH='${mongodb_dir}/bin:${mongosh_dir}/bin:'"'$PATH' \ + | tee >&2 mongo.path + +. mongo.path + +echo >&2 "MongoDB is installed at: ${mongodb_dir}" +mongod >&2 --version + +echo >&2 "MongoDB Shell is installed at: ${mongosh_dir}" +mongosh >&2 --version -mongodb_dir=$(find ${PWD}/ -type d -name "mongodb-linux-x86_64*") -$mongodb_dir/bin/mongod --version +# Cleanup +echo >&2 "Cleaning up..." +rm -f "$mongodb_tarball" "$mongosh_tarball" diff --git a/.github/workflows/start_mongo.sh b/.github/workflows/start_mongo.sh index f493f37a5..3986065e0 100644 --- a/.github/workflows/start_mongo.sh +++ b/.github/workflows/start_mongo.sh @@ -1,14 +1,25 @@ #!/bin/bash +set -e # Exit immediately if a command exits with a non-zero status +set -u # Treat unset variables as an error + +. mongo.path + MONGODB=$1 -mongodb_dir=$(find ${PWD}/ -type d -name "mongodb-linux-x86_64*") +mongodb_dir=$(find ${PWD}/ -type d -name "mongodb-linux-x86_64*" -print -quit) mkdir $mongodb_dir/data -$mongodb_dir/bin/mongod --dbpath $mongodb_dir/data --logpath $mongodb_dir/mongodb.log --fork -if (( $(echo "$MONGODB < 6.0" | bc -l) )); then -mongo --quiet --eval 'db.runCommand("ping").ok' # Make sure mongo is awake -else -mongosh --quiet --eval 'db.runCommand("ping").ok' # Make sure mongo is awake +args=(--dbpath $mongodb_dir/data --logpath $mongodb_dir/mongodb.log --fork --replSet mongoengine) + +# Parse version components +MAJOR=$(echo "$MONGODB" | cut -d'.' -f1) +MINOR=$(echo "$MONGODB" | cut -d'.' -f2) +if [ "$MAJOR" -gt 3 ] || ([ "$MAJOR" -eq 3 ] && [ "$MINOR" -ge 8 ]); then + args+=(--setParameter maxTransactionLockRequestTimeoutMillis=1000) fi + +mongod "${args[@]}" +mongosh --verbose --eval "rs.initiate()" +mongosh --quiet --eval "rs.status().ok" diff --git a/README.rst b/README.rst index d7cf6d3d6..b81e6b44c 100644 --- a/README.rst +++ b/README.rst @@ -35,10 +35,10 @@ an `API reference `_. Supported MongoDB 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. +MongoEngine is currently tested against MongoDB v4.4, v5.0, v6.0, v7.0 and +v8.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. Installation ============ From a362dddc72ba189b3797a7b87fb0a66ea96b0877 Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Tue, 10 Mar 2026 15:15:18 +0100 Subject: [PATCH 13/16] fix tests --- .github/workflows/github-actions.yml | 1 - README.rst | 4 +-- mongoengine/connection.py | 40 ++++++++++++++++------------ tests/test_connection.py | 5 +++- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 0c14c6536..5c4c3f5af 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -17,7 +17,6 @@ env: MONGODB_5_0: "5.0.31" MONGODB_6_0: "6.0.22" MONGODB_7_0: "7.0.19" - MONGODB_8_0: "8.0.9" PYMONGO_3_4: 3.4 PYMONGO_3_6: 3.6 diff --git a/README.rst b/README.rst index b81e6b44c..79d17191f 100644 --- a/README.rst +++ b/README.rst @@ -35,8 +35,8 @@ an `API reference `_. Supported MongoDB Versions ========================== -MongoEngine is currently tested against MongoDB v4.4, v5.0, v6.0, v7.0 and -v8.0. Future versions should be supported as well, but aren't actively tested +MongoEngine is currently tested against MongoDB 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/mongoengine/connection.py b/mongoengine/connection.py index 2f07b83dd..13fa86930 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -136,16 +136,22 @@ def _get_connection_settings( if uri_dict.get(param): conn_settings[param] = uri_dict[param] - uri_options = uri_dict[ - "options" - ] # uri_options is a _CaseInsensitiveDictionary - if "replicaset" in uri_options: - conn_settings["replicaSet"] = uri_options["replicaset"] - if "authsource" in uri_options: - conn_settings["authentication_source"] = uri_options["authsource"] - if "authmechanism" in uri_options: - conn_settings["authentication_mechanism"] = uri_options["authmechanism"] - if "readpreference" in uri_options: + uri_options = uri_dict["options"] + normalized_uri_options = { + key.lower(): value for key, value in uri_options.items() + } + + if "replicaset" in normalized_uri_options: + conn_settings["replicaSet"] = normalized_uri_options["replicaset"] + if "authsource" in normalized_uri_options: + conn_settings["authentication_source"] = normalized_uri_options[ + "authsource" + ] + if "authmechanism" in normalized_uri_options: + conn_settings["authentication_mechanism"] = normalized_uri_options[ + "authmechanism" + ] + if "readpreference" in normalized_uri_options: read_preferences = ( ReadPreference.NEAREST, ReadPreference.PRIMARY, @@ -159,7 +165,7 @@ def _get_connection_settings( # int (e.g. 3). # TODO simplify the code below once we drop support for # PyMongo v3.4. - read_pf_mode = uri_options["readpreference"] + read_pf_mode = normalized_uri_options["readpreference"] if isinstance(read_pf_mode, str): read_pf_mode = read_pf_mode.lower() for preference in read_preferences: @@ -170,23 +176,23 @@ def _get_connection_settings( ReadPrefClass = preference.__class__ break - if "readpreferencetags" in uri_options: + if "readpreferencetags" in normalized_uri_options: conn_settings["read_preference"] = ReadPrefClass( - tag_sets=uri_options["readpreferencetags"] + tag_sets=normalized_uri_options["readpreferencetags"] ) else: conn_settings["read_preference"] = ReadPrefClass() - if "authmechanismproperties" in uri_options: - conn_settings["authmechanismproperties"] = uri_options[ + if "authmechanismproperties" in normalized_uri_options: + conn_settings["authmechanismproperties"] = normalized_uri_options[ "authmechanismproperties" ] - if "uuidrepresentation" in uri_options: + if "uuidrepresentation" in normalized_uri_options: REV_UUID_REPRESENTATIONS = { v: k for k, v in _UUID_REPRESENTATIONS.items() } conn_settings["uuidrepresentation"] = REV_UUID_REPRESENTATIONS[ - uri_options["uuidrepresentation"] + normalized_uri_options["uuidrepresentation"] ] else: resolved_hosts.append(entity) diff --git a/tests/test_connection.py b/tests/test_connection.py index 5b47383b4..450928b5c 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -653,7 +653,10 @@ def test_multiple_connection_settings(self): mongo_connections["t1"].server_info() mongo_connections["t2"].server_info() assert mongo_connections["t1"].address[0] == "localhost" - assert mongo_connections["t2"].address[0] == "127.0.0.1" + assert mongoengine.connection._connection_settings["t2"]["host"] == [ + "127.0.0.1" + ] + assert mongo_connections["t1"] is not mongo_connections["t2"] def test_connect_2_databases_uses_same_client_if_only_dbname_differs(self): c1 = connect(alias="testdb1", db="testdb1") From a5fb2bdd7760355d925001dd105ce7d5639af7d3 Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Tue, 10 Mar 2026 13:14:18 +0100 Subject: [PATCH 14/16] prepare 0.29.3 release --- CONTRIBUTING.rst | 2 +- docs/changelog.rst | 1 - docs/conf.py | 2 +- setup.py | 2 +- tests/document/test_dynamic.py | 2 +- tests/document/test_instance.py | 2 +- tests/document/test_json_serialisation.py | 2 +- tests/queryset/test_queryset.py | 2 +- 8 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 5bda87613..8aa6dd1b3 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -95,7 +95,7 @@ Documentation ------------- To contribute to the `API documentation -`_ +`_ just make your changes to the inline documentation of the appropriate `source code `_ or `rst file `_ in a diff --git a/docs/changelog.rst b/docs/changelog.rst index b360fcbea..e6fb0795c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,7 +8,6 @@ Development =========== - (Fill this out as you fix issues and develop your features). - Changes in 0.29.2 ================= - Remove mentions of mongoengine[dot]org has we no longer own it #2905 diff --git a/docs/conf.py b/docs/conf.py index 808deaa8b..d52ecb2be 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -100,7 +100,7 @@ # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -html_theme_options = {"canonical_url": "http://docs.mongoengine.org/en/latest/"} +html_theme_options = {"canonical_url": "https://mongoengine-odm.readthedocs.io/"} # Add any paths that contain custom themes here, relative to this directory. html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] diff --git a/setup.py b/setup.py index a629d5b12..0ad19787c 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ def get_version(version_tuple): author_email="harry.marr@gmail.com", maintainer="Bastien Gerard", maintainer_email="bast.gerard@gmail.com", - url="http://mongoengine.org/", + url="https://github.com/MongoEngine/mongoengine", download_url="https://github.com/MongoEngine/mongoengine/tarball/master", license="MIT", include_package_data=True, diff --git a/tests/document/test_dynamic.py b/tests/document/test_dynamic.py index 170b2ea3d..34f792369 100644 --- a/tests/document/test_dynamic.py +++ b/tests/document/test_dynamic.py @@ -211,7 +211,7 @@ class Doc(DynamicDocument): Doc.drop_collection() doc = Doc() - embedded_doc_1 = Embedded(content="http://mongoengine.org") + embedded_doc_1 = Embedded(content="http://garbage.org") embedded_doc_1.validate() embedded_doc_2 = Embedded(content="this is not a url") diff --git a/tests/document/test_instance.py b/tests/document/test_instance.py index 54c4bb37d..ddfe45d0d 100644 --- a/tests/document/test_instance.py +++ b/tests/document/test_instance.py @@ -1499,7 +1499,7 @@ class Doc(Document): map_field = MapField(IntField(), default=lambda: {"simple": 1}) decimal_field = DecimalField(default=1.0) complex_datetime_field = ComplexDateTimeField(default=datetime.now) - url_field = URLField(default="http://mongoengine.org") + url_field = URLField(default="http://garbage.org") dynamic_field = DynamicField(default=1) generic_reference_field = GenericReferenceField( default=lambda: Simple().save() diff --git a/tests/document/test_json_serialisation.py b/tests/document/test_json_serialisation.py index 61298ab17..be9e9bcef 100644 --- a/tests/document/test_json_serialisation.py +++ b/tests/document/test_json_serialisation.py @@ -79,7 +79,7 @@ class Doc(Document): map_field = MapField(IntField(), default=lambda: {"simple": 1}) decimal_field = DecimalField(default=1.0) complex_datetime_field = ComplexDateTimeField(default=datetime.now) - url_field = URLField(default="http://mongoengine.org") + url_field = URLField(default="http://garbage.org") dynamic_field = DynamicField(default=1) generic_reference_field = GenericReferenceField( default=lambda: Simple().save() diff --git a/tests/queryset/test_queryset.py b/tests/queryset/test_queryset.py index 7b41a894b..b1038247b 100644 --- a/tests/queryset/test_queryset.py +++ b/tests/queryset/test_queryset.py @@ -5162,7 +5162,7 @@ class Doc(Document): map_field = MapField(IntField(), default=lambda: {"simple": 1}) decimal_field = DecimalField(default=1.0) complex_datetime_field = ComplexDateTimeField(default=datetime.datetime.now) - url_field = URLField(default="http://mongoengine.org") + url_field = URLField(default="http://garbage.org") dynamic_field = DynamicField(default=1) generic_reference_field = GenericReferenceField( default=lambda: Simple().save() From 30f6d56c5c0777f084213faf6b6e923acea225f7 Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Tue, 10 Mar 2026 16:05:20 +0100 Subject: [PATCH 15/16] prep release 0.29.3 --- docs/changelog.rst | 6 +++++- mongoengine/__init__.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index e6fb0795c..881520899 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,10 +8,14 @@ Development =========== - (Fill this out as you fix issues and develop your features). -Changes in 0.29.2 +Changes in 0.29.3 ================= - Remove mentions of mongoengine[dot]org has we no longer own it #2905 +Changes in 0.29.2 +================= +- fixes relted with + Changes in 0.29.1 ================= - Add support for freshly released pymongo 4.9 #2849 diff --git a/mongoengine/__init__.py b/mongoengine/__init__.py index 978eebc5e..bda28f1ee 100644 --- a/mongoengine/__init__.py +++ b/mongoengine/__init__.py @@ -29,7 +29,7 @@ ) -VERSION = (0, 29, 2) +VERSION = (0, 29, 3) def get_version(): From 6b979cf89efd64dc0e9a35f5eccac57221b3385b Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Sat, 15 Aug 2026 14:35:22 +0200 Subject: [PATCH 16/16] Fix accidental bug that prevented the examples from rendering in the readme --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 1b675012c..4d21b4c0c 100644 --- a/README.rst +++ b/README.rst @@ -83,6 +83,7 @@ Examples Some simple examples of what MongoEngine code looks like: .. code :: python + import datetime from mongoengine import *