Skip to content

Commit

Permalink
Merge pull request #2849 from efrederickson/patch-1
Browse files Browse the repository at this point in the history
Update to support pymongo 4.9
  • Loading branch information
bagerard authored Sep 19, 2024
2 parents 75e7779 + 673b572 commit 4dd8432
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }}
Expand Down
6 changes: 5 additions & 1 deletion mongoengine/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions tests/fields/test_datetime_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions tests/queryset/test_queryset_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 6 additions & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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

0 comments on commit 4dd8432

Please sign in to comment.