diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index ad601746a..8ab674667 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 @@ -42,8 +43,8 @@ jobs: # which runs pre-configured linter & autoformatter runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '3.9' check-latest: true @@ -88,10 +89,13 @@ 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@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} check-latest: true @@ -108,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 @@ -119,9 +123,9 @@ jobs: # builds are visible at https://readthedocs.org/projects/mongoengine-odm/builds/ runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.9 check-latest: true @@ -138,8 +142,8 @@ jobs: runs-on: ubuntu-latest needs: [linting, test, build_doc_dryrun] steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: 3.9 check-latest: true @@ -153,9 +157,9 @@ jobs: needs: [linting, test, build_doc_dryrun, build-dryrun] if: github.event_name == 'create' && startsWith(github.ref, 'refs/tags/v') steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python 3.9 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.9 check-latest: true 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(): diff --git a/mongoengine/connection.py b/mongoengine/connection.py index 42a79434e..2f07b83dd 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -2,7 +2,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 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" 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