Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ env:
MONGODB_7_0: "7.0.19"
MONGODB_8_0: "8.0.9"

PYMONGO_4_2: "4.2.0"
PYMONGO_4_8: "4.8.0"
PYMONGO_4_10: "4.10.1"
PYMONGO_4_14: "4.14.1"
Expand Down Expand Up @@ -51,10 +52,13 @@ 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:
- python-version: "3.11"
MONGODB: $MONGODB_4_4
PYMONGO: $PYMONGO_4_2
- python-version: "3.11"
MONGODB: $MONGODB_5_0
PYMONGO: $PYMONGO_4_10
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ post to the `user group <http://groups.google.com/group/mongoengine-users>`
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
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -62,7 +62,7 @@ Dependencies
============
MongoEngine requires:

- PyMongo >=4.0
- PyMongo >=4.2, <5.0

The following optional packages enable additional functionality:

Expand Down
7 changes: 4 additions & 3 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,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``.
Expand Down
5 changes: 2 additions & 3 deletions docs/guide/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ Installing MongoEngine

To use MongoEngine, you will need to download `MongoDB <https://www.mongodb.com/>`_
and ensure it is running in an accessible location. You will also need
`PyMongo <http://api.mongodb.org/python>`_ to use MongoEngine, but if you
install MongoEngine using setuptools, then the dependencies will be handled for
you.
`PyMongo <https://pymongo.readthedocs.io/>`_ >=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`:

Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -44,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",
Expand All @@ -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,
Expand Down
39 changes: 15 additions & 24 deletions tests/document/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 4 additions & 12 deletions tests/fields/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions tests/queryset/test_queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import functools
import operator
import unittest
from datetime import datetime, timezone
from datetime import UTC, datetime

import pymongo
import pytest

from mongoengine import connect
from mongoengine.connection import disconnect_all, get_db
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


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):
Expand Down
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[tox]
envlist =
pypy3-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170}
py{310,311,312,313,314}-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170}
py311-mg420
pypy311-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170}
py{311,312,313,314}-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170}
skipsdist = True

[testenv]
commands =
pytest tests/ {posargs}
deps =
-rrequirements-dev.txt
mg420: pymongo==4.2.0
mg480: pymongo>=4.8,<4.9
mg4101: pymongo>=4.10,<4.11
mg4141: pymongo>=4.14,<4.15
Expand Down