From c72020c0c54f1a17ab374d192c6d02fb03eda230 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 27 Nov 2026 22:58:47 +0000 Subject: [PATCH 1/6] Drop Python 3.10 support --- .github/workflows/github-actions.yml | 2 +- .pre-commit-config.yaml | 2 +- CONTRIBUTING.rst | 2 +- README.rst | 2 +- docs/changelog.rst | 1 + setup.py | 3 +-- tests/fields/test_fields.py | 16 ++++------------ tests/queryset/test_queryset.py | 4 ++-- tests/utils.py | 4 ++-- tox.ini | 4 ++-- 10 files changed, 16 insertions(+), 24 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index ea4e4d336..bf41c8a4f 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -51,7 +51,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "pypy3.10"] + python-version: ["3.11", "3.12", "3.13", "3.14", "pypy3.11"] MONGODB: [$MONGODB_4_4] PYMONGO: [$PYMONGO_4_8] include: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index faf1ee2ee..3061a773e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: rev: v3.21.2 hooks: - id: pyupgrade - args: [--py310-plus] + args: [--py311-plus] - repo: https://github.com/pycqa/isort rev: 9.0.0a3 hooks: diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 6a7e267c7..d3f5e1d79 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -20,7 +20,7 @@ post to the `user group ` Supported Interpreters ---------------------- -MongoEngine supports CPython 3.5 and newer as well as Pypy3. +MongoEngine supports CPython and PyPy with Python 3.11 or newer. Language features not supported by all interpreters can not be used. Python3 codebase diff --git a/README.rst b/README.rst index 215423266..3b7246736 100644 --- a/README.rst +++ b/README.rst @@ -49,7 +49,7 @@ experience any problems with more recent MongoDB versions. Installation ============ -MongoEngine requires Python 3.10 or newer. Install it from PyPI with: +MongoEngine requires Python 3.11 or newer. Install it from PyPI with: .. code-block:: console diff --git a/docs/changelog.rst b/docs/changelog.rst index bfaeab77f..5f32665fe 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,6 +7,7 @@ Changelog Development =========== - (Fill this out as you fix issues and develop your features). +- BREAKING CHANGE: Drop support for Python 3.10. Python 3.11 or newer is required. - Fix partial ``Document.reload()`` leaving custom ``db_field`` values marked as changed. Changes in 1.0.0 diff --git a/setup.py b/setup.py index f7f7021ce..086b157f3 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,6 @@ def get_version(version_tuple): "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", @@ -68,7 +67,7 @@ def get_version(version_tuple): long_description=LONG_DESCRIPTION, platforms=["any"], classifiers=CLASSIFIERS, - python_requires=">=3.10", + python_requires=">=3.11", install_requires=install_require, extras_require={ "test": tests_require, diff --git a/tests/fields/test_fields.py b/tests/fields/test_fields.py index e6f0f7590..806052253 100644 --- a/tests/fields/test_fields.py +++ b/tests/fields/test_fields.py @@ -89,9 +89,7 @@ class Person(Document): name = StringField() age = IntField(default=30, required=False) userid = StringField(default=lambda: "test", required=True) - created = DateTimeField( - default=lambda: datetime.datetime.now(datetime.timezone.utc) - ) + created = DateTimeField(default=lambda: datetime.datetime.now(datetime.UTC)) day = DateField(default=datetime.date.today) person = Person(name="Ross") @@ -171,9 +169,7 @@ class Person(Document): name = StringField() age = IntField(default=30, required=False) userid = StringField(default=lambda: "test", required=True) - created = DateTimeField( - default=lambda: datetime.datetime.now(datetime.timezone.utc) - ) + created = DateTimeField(default=lambda: datetime.datetime.now(datetime.UTC)) # Trying setting values to None person = Person(name=None, age=None, userid=None, created=None) @@ -207,9 +203,7 @@ class Person(Document): name = StringField() age = IntField(default=30, required=False) userid = StringField(default=lambda: "test", required=True) - created = DateTimeField( - default=lambda: datetime.datetime.now(datetime.timezone.utc) - ) + created = DateTimeField(default=lambda: datetime.datetime.now(datetime.UTC)) person = Person() person.name = None @@ -277,9 +271,7 @@ class Person(Document): name = StringField() age = IntField(default=30, required=False) userid = StringField(default=lambda: "test", required=True) - created = DateTimeField( - default=lambda: datetime.datetime.now(datetime.timezone.utc) - ) + created = DateTimeField(default=lambda: datetime.datetime.now(datetime.UTC)) person = Person( name="Ross", diff --git a/tests/queryset/test_queryset.py b/tests/queryset/test_queryset.py index 64bfcc76f..c5302dca3 100644 --- a/tests/queryset/test_queryset.py +++ b/tests/queryset/test_queryset.py @@ -1556,7 +1556,7 @@ class BlogPost(Document): BlogPost.objects.create( title="whatever", - published_date=datetime.datetime.now(datetime.timezone.utc), + published_date=datetime.datetime.now(datetime.UTC), ) with db_ops_tracker() as q: @@ -3165,7 +3165,7 @@ class Link(Document): Link.drop_collection() - now = datetime.datetime.now(datetime.timezone.utc) + now = datetime.datetime.now(datetime.UTC) # Note: Test data taken from a custom Reddit homepage on # Fri, 12 Feb 2010 14:36:00 -0600. Link ordering should diff --git a/tests/utils.py b/tests/utils.py index daee1395e..c83fbebc4 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,7 +1,7 @@ import functools import operator import unittest -from datetime import datetime, timezone +from datetime import UTC, datetime import pymongo import pytest @@ -18,7 +18,7 @@ def utcnow_naive() -> datetime: """Return the current UTC datetime without timezone information.""" - return datetime.now(timezone.utc).replace(tzinfo=None) + return datetime.now(UTC).replace(tzinfo=None) class MongoDBTestCase(unittest.TestCase): diff --git a/tox.ini b/tox.ini index 504020c2a..9d8421408 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist = - pypy3-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170} - py{310,311,312,313,314}-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170} + pypy311-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170} + py{311,312,313,314}-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170} skipsdist = True [testenv] From bc43934caf5e47250da009fa01713ffa5d266910 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 27 Nov 2026 22:39:28 +0000 Subject: [PATCH 2/6] Remove unused PyMongo version helper --- tests/utils.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index c83fbebc4..a5fdba027 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -3,7 +3,6 @@ import unittest from datetime import UTC, datetime -import pymongo import pytest from mongoengine import connect @@ -11,8 +10,6 @@ from mongoengine.context_managers import query_counter from mongoengine.mongodb_support import get_mongodb_version -PYMONGO_VERSION = tuple(pymongo.version_tuple[:2]) - MONGO_TEST_DB = "mongoenginetest" # standard name for the test database From 1009a52d32f98a75759ba6ea0a6467d0b6971fb1 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 27 Nov 2026 22:39:28 +0000 Subject: [PATCH 3/6] Test the minimum supported PyMongo version --- .github/workflows/github-actions.yml | 4 ++++ tox.ini | 2 ++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index bf41c8a4f..6c5aede75 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -19,6 +19,7 @@ env: MONGODB_7_0: "7.0.19" MONGODB_8_0: "8.0.9" + PYMONGO_4_0: "4.0.0" PYMONGO_4_8: "4.8.0" PYMONGO_4_10: "4.10.1" PYMONGO_4_14: "4.14.1" @@ -55,6 +56,9 @@ jobs: MONGODB: [$MONGODB_4_4] PYMONGO: [$PYMONGO_4_8] include: + - python-version: "3.11" + MONGODB: $MONGODB_4_4 + PYMONGO: $PYMONGO_4_0 - python-version: "3.11" MONGODB: $MONGODB_5_0 PYMONGO: $PYMONGO_4_10 diff --git a/tox.ini b/tox.ini index 9d8421408..d928a1800 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,6 @@ [tox] envlist = + py311-mg400 pypy311-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170} py{311,312,313,314}-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170} skipsdist = True @@ -9,6 +10,7 @@ commands = pytest tests/ {posargs} deps = -rrequirements-dev.txt + mg400: pymongo==4.0.0 mg480: pymongo>=4.8,<4.9 mg4101: pymongo>=4.10,<4.11 mg4141: pymongo>=4.14,<4.15 From c434813332886d9d62551fc802343d4b228c4c99 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 27 Nov 2026 22:39:28 +0000 Subject: [PATCH 4/6] Document supported PyMongo versions --- README.rst | 2 +- docs/guide/installing.rst | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 3b7246736..65afe5780 100644 --- a/README.rst +++ b/README.rst @@ -62,7 +62,7 @@ Dependencies ============ MongoEngine requires: -- PyMongo >=4.0 +- PyMongo >=4.0, <5.0 The following optional packages enable additional functionality: diff --git a/docs/guide/installing.rst b/docs/guide/installing.rst index efdb46fd4..00a654afc 100644 --- a/docs/guide/installing.rst +++ b/docs/guide/installing.rst @@ -4,9 +4,8 @@ Installing MongoEngine To use MongoEngine, you will need to download `MongoDB `_ and ensure it is running in an accessible location. You will also need -`PyMongo `_ to use MongoEngine, but if you -install MongoEngine using setuptools, then the dependencies will be handled for -you. +`PyMongo `_ >=4.0, <5.0 to use MongoEngine. +When you install MongoEngine with pip, its dependencies are installed for you. MongoEngine is available on PyPI, so you can use :program:`pip`: From c35c2be3c655f40210e8708bb91b9b0127bddda7 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 27 Nov 2026 22:47:37 +0000 Subject: [PATCH 5/6] Require PyMongo 4.2 or newer --- .github/workflows/github-actions.yml | 4 +-- README.rst | 2 +- docs/changelog.rst | 6 ++--- docs/guide/installing.rst | 2 +- setup.py | 2 +- tests/document/test_instance.py | 39 +++++++++++----------------- tox.ini | 4 +-- 7 files changed, 25 insertions(+), 34 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 6c5aede75..2526cba76 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -19,7 +19,7 @@ env: MONGODB_7_0: "7.0.19" MONGODB_8_0: "8.0.9" - PYMONGO_4_0: "4.0.0" + PYMONGO_4_2: "4.2.0" PYMONGO_4_8: "4.8.0" PYMONGO_4_10: "4.10.1" PYMONGO_4_14: "4.14.1" @@ -58,7 +58,7 @@ jobs: include: - python-version: "3.11" MONGODB: $MONGODB_4_4 - PYMONGO: $PYMONGO_4_0 + PYMONGO: $PYMONGO_4_2 - python-version: "3.11" MONGODB: $MONGODB_5_0 PYMONGO: $PYMONGO_4_10 diff --git a/README.rst b/README.rst index 65afe5780..9a94ffa3d 100644 --- a/README.rst +++ b/README.rst @@ -62,7 +62,7 @@ Dependencies ============ MongoEngine requires: -- PyMongo >=4.0, <5.0 +- PyMongo >=4.2, <5.0 The following optional packages enable additional functionality: diff --git a/docs/changelog.rst b/docs/changelog.rst index 5f32665fe..1c8b3cab9 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -47,9 +47,9 @@ Changes in 1.0.0 - Fix use of $search, $searchMeta, or $vectorSearch in aggregate #2878 - BugFix - Fix use of $geoNear or $collStats in aggregate #2493 - BREAKING CHANGE: Further to the deprecation warning, remove ability to use an unpacked list to `Queryset.aggregate(*pipeline)`, a plain list must be provided instead `Queryset.aggregate(pipeline)`, as it's closer to pymongo interface -- BREAKING CHANGE: PyMongo 3.x is no longer supported. As PyMongo 3.x is now - quite old, this is unlikely to affect most users. The consequences below - concern functionality that already did not work with PyMongo 4.x: +- BREAKING CHANGE: PyMongo versions older than 4.2 are no longer supported. + The consequences below concern functionality that already did not work with + PyMongo 4.x: - ``QuerySet.count()`` no longer supports queries using ``$near``, ``$nearSphere``, ``$geoNear``, or ``$where``. PyMongo's``count_documents()`` rejects these operators and raises ``OperationFailure``; the removed ``Cursor.count()`` fallback is no longer available. Use ``$geoWithin`` with ``$center`` or ``$centerSphere`` for countable geospatial filters, and ``$expr`` instead of ``$where``. diff --git a/docs/guide/installing.rst b/docs/guide/installing.rst index 00a654afc..fa2bbd2c1 100644 --- a/docs/guide/installing.rst +++ b/docs/guide/installing.rst @@ -4,7 +4,7 @@ Installing MongoEngine To use MongoEngine, you will need to download `MongoDB `_ and ensure it is running in an accessible location. You will also need -`PyMongo `_ >=4.0, <5.0 to use MongoEngine. +`PyMongo `_ >=4.2, <5.0 to use MongoEngine. When you install MongoEngine with pip, its dependencies are installed for you. MongoEngine is available on PyPI, so you can use :program:`pip`: diff --git a/setup.py b/setup.py index 086b157f3..1a60ffb77 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ def get_version(version_tuple): "Topic :: Software Development :: Libraries :: Python Modules", ] -install_require = ["pymongo>=4.0,<5.0"] +install_require = ["pymongo>=4.2,<5.0"] tests_require = [ "pytest", "pytest-cov", diff --git a/tests/document/test_instance.py b/tests/document/test_instance.py index 9b4d3b672..d3e49b8f7 100644 --- a/tests/document/test_instance.py +++ b/tests/document/test_instance.py @@ -30,10 +30,7 @@ MONGODB_36, get_mongodb_version, ) -from mongoengine.pymongo_support import ( - PYMONGO_VERSION, - list_collection_names, -) +from mongoengine.pymongo_support import list_collection_names from mongoengine.queryset import NULLIFY, Q from tests import fixtures from tests.fixtures import ( @@ -2019,16 +2016,13 @@ class AggPerson(Document): comment = "test_comment" - if PYMONGO_VERSION >= (4, 1): - with db_ops_tracker() as q: - _ = AggPerson.objects.comment(comment).update_one(name="something") - query_op = q.db.system.profile.find( - {"ns": "mongoenginetest.agg_person"} - )[0] - CMD_QUERY_KEY = "command" if mongo_ver >= MONGODB_36 else "query" - assert "hint" not in query_op[CMD_QUERY_KEY] - assert query_op[CMD_QUERY_KEY]["comment"] == comment - assert "collation" not in query_op[CMD_QUERY_KEY] + with db_ops_tracker() as q: + _ = AggPerson.objects.comment(comment).update_one(name="something") + query_op = q.db.system.profile.find({"ns": "mongoenginetest.agg_person"})[0] + CMD_QUERY_KEY = "command" if mongo_ver >= MONGODB_36 else "query" + assert "hint" not in query_op[CMD_QUERY_KEY] + assert query_op[CMD_QUERY_KEY]["comment"] == comment + assert "collation" not in query_op[CMD_QUERY_KEY] with db_ops_tracker() as q: _ = AggPerson.objects.hint(index_name).update_one(name="something") @@ -2074,16 +2068,13 @@ class AggPerson(Document): comment = "test_comment" - if PYMONGO_VERSION >= (4, 1): - with db_ops_tracker() as q: - _ = AggPerson.objects().comment(comment).delete() - query_op = q.db.system.profile.find( - {"ns": "mongoenginetest.agg_person"} - )[0] - CMD_QUERY_KEY = "command" if mongo_ver >= MONGODB_36 else "query" - assert "hint" not in query_op[CMD_QUERY_KEY] - assert query_op[CMD_QUERY_KEY]["comment"] == comment - assert "collation" not in query_op[CMD_QUERY_KEY] + with db_ops_tracker() as q: + _ = AggPerson.objects().comment(comment).delete() + query_op = q.db.system.profile.find({"ns": "mongoenginetest.agg_person"})[0] + CMD_QUERY_KEY = "command" if mongo_ver >= MONGODB_36 else "query" + assert "hint" not in query_op[CMD_QUERY_KEY] + assert query_op[CMD_QUERY_KEY]["comment"] == comment + assert "collation" not in query_op[CMD_QUERY_KEY] with db_ops_tracker() as q: _ = AggPerson.objects.hint(index_name).delete() diff --git a/tox.ini b/tox.ini index d928a1800..0db33776a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py311-mg400 + py311-mg420 pypy311-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170} py{311,312,313,314}-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170} skipsdist = True @@ -10,7 +10,7 @@ commands = pytest tests/ {posargs} deps = -rrequirements-dev.txt - mg400: pymongo==4.0.0 + mg420: pymongo==4.2.0 mg480: pymongo>=4.8,<4.9 mg4101: pymongo>=4.10,<4.11 mg4141: pymongo>=4.14,<4.15 From 02cb72d3241332a6ed421fdc845a9e3c6f2f3c2c Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 27 Nov 2026 23:01:00 +0000 Subject: [PATCH 6/6] Simplify range in queryset test --- tests/queryset/test_queryset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/queryset/test_queryset.py b/tests/queryset/test_queryset.py index c5302dca3..379447068 100644 --- a/tests/queryset/test_queryset.py +++ b/tests/queryset/test_queryset.py @@ -4341,7 +4341,7 @@ class MyDoc(Document): pass MyDoc.drop_collection() - for i in range(0, 10): + for i in range(10): MyDoc().save() assert MyDoc.objects.count() == 10