diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 6073bb6cd..8c3e441e3 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -19,19 +19,14 @@ env: MONGODB_7_0: "7.0.19" MONGODB_8_0: "8.0.9" - PYMONGO_3_12: "3.12.3" - PYMONGO_3_13: "3.13.0" - PYMONGO_4_0: "4.0.2" - PYMONGO_4_3: "4.3.3" - PYMONGO_4_4: "4.4.1" - PYMONGO_4_6: "4.6.2" - PYMONGO_4_7: "4.7.3" PYMONGO_4_8: "4.8.0" - PYMONGO_4_9: "4.9.2" PYMONGO_4_10: "4.10.1" - PYMONGO_4_11: "4.11.2" + PYMONGO_4_14: "4.14.1" + PYMONGO_4_15: "4.15.5" + PYMONGO_4_16: "4.16.0" + PYMONGO_4_17: "4.17.0" - MAIN_PYTHON_VERSION: "3.9" + MAIN_PYTHON_VERSION: "3.14" jobs: linting: @@ -39,8 +34,8 @@ jobs: # which runs pre-configured linter & autoformatter runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 with: python-version: ${{ env.MAIN_PYTHON_VERSION }} check-latest: true @@ -54,53 +49,29 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.9", "pypy3.10"] + python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "pypy3.10"] MONGODB: [$MONGODB_4_4] - PYMONGO: [$PYMONGO_3_12] + PYMONGO: [$PYMONGO_4_8] include: - - python-version: "3.9" - MONGODB: $MONGODB_4_4 - PYMONGO: $PYMONGO_3_13 - - python-version: "3.10" - MONGODB: $MONGODB_4_4 - PYMONGO: $PYMONGO_4_0 - python-version: "3.11" MONGODB: $MONGODB_5_0 - PYMONGO: $PYMONGO_4_3 - - python-version: "3.11" - MONGODB: $MONGODB_6_0 - PYMONGO: $PYMONGO_4_4 - - python-version: "3.11" - MONGODB: $MONGODB_7_0 - PYMONGO: $PYMONGO_4_6 - - python-version: "3.11" - MONGODB: $MONGODB_7_0 - PYMONGO: $PYMONGO_4_7 - - python-version: "3.11" - MONGODB: $MONGODB_7_0 - PYMONGO: $PYMONGO_4_8 - - python-version: "3.11" - MONGODB: $MONGODB_7_0 - PYMONGO: $PYMONGO_4_9 - - python-version: "3.12" - MONGODB: $MONGODB_7_0 - PYMONGO: $PYMONGO_4_9 + PYMONGO: $PYMONGO_4_10 - python-version: "3.12" - MONGODB: $MONGODB_8_0 - PYMONGO: $PYMONGO_4_9 + MONGODB: $MONGODB_6_0 + PYMONGO: $PYMONGO_4_14 - python-version: "3.13" - MONGODB: $MONGODB_8_0 - PYMONGO: $PYMONGO_4_9 + MONGODB: $MONGODB_7_0 + PYMONGO: $PYMONGO_4_15 - python-version: "3.13" MONGODB: $MONGODB_8_0 - PYMONGO: $PYMONGO_4_10 - - python-version: "3.13" + PYMONGO: $PYMONGO_4_16 + - python-version: "3.14" MONGODB: $MONGODB_8_0 - PYMONGO: $PYMONGO_4_11 + PYMONGO: $PYMONGO_4_17 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} check-latest: true @@ -127,9 +98,9 @@ jobs: # builds are visible at https://readthedocs.org/projects/mongoengine-odm/builds/ runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: python-version: ${{ env.MAIN_PYTHON_VERSION }} check-latest: true @@ -146,14 +117,14 @@ jobs: runs-on: ubuntu-latest needs: [linting, test, build_doc_dryrun] steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 with: python-version: ${{ env.MAIN_PYTHON_VERSION }} check-latest: true - name: build dummy wheel for test-pypi run: | - pip install wheel + pip install setuptools wheel python setup.py sdist bdist_wheel build-n-publish: @@ -161,9 +132,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@v4 + - uses: actions/checkout@v6 - name: Set up Python ${{ env.MAIN_PYTHON_VERSION }} - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: python-version: ${{ env.MAIN_PYTHON_VERSION }} check-latest: true @@ -171,7 +142,7 @@ jobs: # https://stackoverflow.com/questions/59349905/which-properties-does-github-event-in-a-github-workflow-have - name: build dummy wheel for test-pypi run: | - pip install wheel + pip install setuptools wheel python setup.py sdist bdist_wheel - name: publish pypi uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/install_mongo.sh b/.github/workflows/install_mongo.sh index 8b0798db5..a7b81b7a1 100644 --- a/.github/workflows/install_mongo.sh +++ b/.github/workflows/install_mongo.sh @@ -65,6 +65,8 @@ if [ ! -d "$mongosh_dir" ]; then exit 1 fi +# creating a ".path" file to make sure start_mongo is referring to the same binaries +# that this installation is referring to echo >&2 "Creating mongo.path" echo "export PATH='${mongodb_dir}/bin:${mongosh_dir}/bin:'"'$PATH' \ | tee >&2 mongo.path diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f44ee04b..faf1ee2ee 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,28 +1,28 @@ fail_fast: false repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: check-merge-conflict - id: debug-statements - id: trailing-whitespace - id: end-of-file-fixer - repo: https://github.com/ambv/black - rev: 25.1.0 + rev: 26.5.1 hooks: - id: black - repo: https://github.com/pycqa/flake8 - rev: 7.2.0 + rev: 7.3.0 hooks: - id: flake8 additional_dependencies: - importlib_metadata<5 - repo: https://github.com/asottile/pyupgrade - rev: v3.19.1 + rev: v3.21.2 hooks: - id: pyupgrade - args: [--py36-plus] + args: [--py310-plus] - repo: https://github.com/pycqa/isort - rev: 6.0.1 + rev: 9.0.0a3 hooks: - id: isort diff --git a/docker-compose.yml b/docker-compose.yml index 8b3b36101..d1d07a282 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,3 +5,7 @@ services: image: mongoengine:latest ports: - 27017:27017 + ulimits: + nofile: + soft: 64000 + hard: 64000 diff --git a/mongoengine/base/common.py b/mongoengine/base/common.py index fe631a40e..b3991528d 100644 --- a/mongoengine/base/common.py +++ b/mongoengine/base/common.py @@ -47,14 +47,11 @@ def get(name): if len(possible_match) == 1: doc = _document_registry.get(possible_match.pop(), None) if not doc: - raise NotRegistered( - """ + raise NotRegistered(""" `%s` has not been registered in the document registry. Importing the document class automatically registers it, has it been imported? - """.strip() - % name - ) + """.strip() % name) return doc @staticmethod diff --git a/mongoengine/connection.py b/mongoengine/connection.py index a24f0cc36..9c3330c3d 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -139,9 +139,12 @@ def _get_connection_settings( if uri_dict.get(param): conn_settings[param] = uri_dict[param] - uri_options = uri_dict[ - "options" - ] # uri_options is a _CaseInsensitiveDictionary + # PyMongo < 4.14 returned a case-insensitive options mapping, but + # PyMongo >= 4.14 returns a plain dict with canonical option names. + # Normalize keys so lookups stay compatible across supported versions. + uri_options = { + key.lower(): value for key, value in uri_dict["options"].items() + } if "replicaset" in uri_options: conn_settings["replicaSet"] = uri_options["replicaset"] if "authsource" in uri_options: diff --git a/mongoengine/queryset/base.py b/mongoengine/queryset/base.py index 2db97ddb7..21d64564d 100644 --- a/mongoengine/queryset/base.py +++ b/mongoengine/queryset/base.py @@ -1866,9 +1866,7 @@ def _item_frequencies_map_reduce(self, field, normalize=False): emit(null, 1); }} }} - """.format( - field=field - ) + """.format(field=field) reduce_func = """ function(key, values) { var total = 0; diff --git a/setup.py b/setup.py index a19e8cab4..7af6b7272 100644 --- a/setup.py +++ b/setup.py @@ -33,11 +33,11 @@ def get_version(version_tuple): "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Database", @@ -68,7 +68,7 @@ def get_version(version_tuple): long_description=LONG_DESCRIPTION, platforms=["any"], classifiers=CLASSIFIERS, - python_requires=">=3.7", + python_requires=">=3.10", install_requires=install_require, extras_require={ "test": tests_require, diff --git a/tests/document/test_instance.py b/tests/document/test_instance.py index c15000726..1d1c0c23d 100644 --- a/tests/document/test_instance.py +++ b/tests/document/test_instance.py @@ -3042,14 +3042,10 @@ def __str__(self): assert susan_karl_books_qs.count() == 1 # $Where - custom_qs = Book.objects.filter( - __raw__={ - "$where": """ + custom_qs = Book.objects.filter(__raw__={"$where": """ function(){ return this.name == '1' || - this.name == '2';}""" - } - ) + this.name == '2';}"""}) assert [str(b) for b in custom_qs] == ["1", "2"] # count only will work with this raw query before pymongo 4.x, but diff --git a/tox.ini b/tox.ini index 2d0c63945..504020c2a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist = - pypy3-{mg3123,mg3130,mg402,mg433,mg441,mg462,mg473,mg480,mg492,mg4101,mg4112} - py{39,310,311,312,313}-{mg3123,mg3130,mg402,mg433,mg441,mg462,mg473,mg480,mg492,mg4101,mg4112} + pypy3-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170} + py{310,311,312,313,314}-{mg480,mg4101,mg4141,mg4155,mg4160,mg4170} skipsdist = True [testenv] @@ -9,16 +9,11 @@ commands = pytest tests/ {posargs} deps = -rrequirements-dev.txt - mg3123: pymongo>=3.12,<3.13 - mg3130: pymongo>=3.13,<3.14 - mg402: pymongo>=4.0,<4.1 - mg433: pymongo>=4.3,<4.4 - mg441: pymongo>=4.4,<4.5 - mg462: pymongo>=4.6,<4.7 - mg473: pymongo>=4.7,<4.8 mg480: pymongo>=4.8,<4.9 - mg492: pymongo>=4.9,<4.10 mg4101: pymongo>=4.10,<4.11 - mg4112: pymongo>=4.11,<4.12 + mg4141: pymongo>=4.14,<4.15 + mg4155: pymongo>=4.15,<4.16 + mg4160: pymongo>=4.16,<4.17 + mg4170: pymongo>=4.17,<4.18 setenv = PYTHON_EGG_CACHE = {envdir}/python-eggs