diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 2d8823c0d..df8d6b25b 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -29,6 +29,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 @@ -83,6 +84,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 }} diff --git a/mongoengine/connection.py b/mongoengine/connection.py index f64422d28..6a2e754b9 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -4,7 +4,11 @@ from pymongo import MongoClient, ReadPreference, uri_parser from pymongo.common import _UUID_REPRESENTATIONS -from pymongo.database 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: diff --git a/tests/fields/test_datetime_field.py b/tests/fields/test_datetime_field.py index ced10b1bc..d04f39b04 100644 --- a/tests/fields/test_datetime_field.py +++ b/tests/fields/test_datetime_field.py @@ -2,15 +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): def test_datetime_from_empty_string(self): 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 34ecb331b..87af2b517 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" diff --git a/tox.ini b/tox.ini index d29267124..0db203642 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