Skip to content

Commit

Permalink
Merge branch 'master' of github.com:MongoEngine/mongoengine into 2784…
Browse files Browse the repository at this point in the history
…_validate_override_embedded_doc
  • Loading branch information
bagerard committed Dec 15, 2023
2 parents c80c25c + 8f865ba commit b7617bb
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 32 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ env:
MONGODB_4_0: 4.0.28
MONGODB_4_4: 4.4
MONGODB_5_0: "5.0"
MONGODB_6_0: "6.0"
MONGODB_7_0: "7.0"

PYMONGO_3_4: 3.4
PYMONGO_3_6: 3.6
Expand All @@ -25,6 +27,8 @@ env:
PYMONGO_3_12: 3.12
PYMONGO_4_0: 4.0
PYMONGO_4_3: 4.3.2
PYMONGO_4_4: 4.4.1
PYMONGO_4_6: 4.6.0

MAIN_PYTHON_VERSION: 3.7

Expand Down Expand Up @@ -68,6 +72,12 @@ jobs:
- 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
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/install_mongo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ elif [[ "$MONGODB" == *"4.4"* ]]; then
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
elif [[ "$MONGODB" == *"5.0"* ]]; then
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
elif [[ "$MONGODB" == *"6.0"* ]]; then
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
elif [[ "$MONGODB" == *"7.0"* ]]; then
mongo_build=mongodb-linux-x86_64-ubuntu2004-v${MONGODB}-latest
fi

wget http://fastdl.mongodb.org/linux/$mongo_build.tgz
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/ambv/black
rev: 23.1.0
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- importlib_metadata<5
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.14.0
hooks:
- id: pyupgrade
args: [--py36-plus]
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ an `API reference <https://mongoengine-odm.readthedocs.io/apireference.html>`_.

Supported MongoDB Versions
==========================
MongoEngine is currently tested against MongoDB v3.6, v4.0, v4.4 and v5.0. Future versions
MongoEngine is currently tested against MongoDB v3.6, v4.0, v4.4, v5.0, v6.0 and v7.0. Future versions
should be supported as well, but aren't actively tested at the moment. Make
sure to open an issue or submit a pull request if you experience any problems
with a more recent MongoDB versions.
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Development
===========
- (Fill this out as you fix issues and develop your features).
- Fix for uuidRepresentation not read when provided in URI #2741
- Add tests against MongoDB 6.0 and MongoDB 7.0 in the pipeline
- Fix validate() not being called when inheritance is used in EmbeddedDocument and validate is overriden #2784

Changes in 0.27.0
Expand Down
6 changes: 3 additions & 3 deletions mongoengine/base/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def __init__(
unique with (Creates an index).
:param primary_key: Mark this field as the primary key ((Creates an index)). Defaults to False.
:param validation: (optional) A callable to validate the value of the
field. The callable takes the value as parameter and should raise
field. The callable takes the value as parameter and should raise
a ValidationError if validation fails
:param choices: (optional) The valid choices
:param null: (optional) If the field value can be null when a default exist. If not set, the default value
will be used in case a field with a default value is set to None. Defaults to False.
:param null: (optional) If the field value can be null when a default exists. If not set, the default value
will be used in case a field with a default value is set to None. Defaults to False.
:param sparse: (optional) `sparse=True` combined with `unique=True` and `required=False`
means that uniqueness won't be enforced for `None` values (Creates an index). Defaults to False.
:param **kwargs: (optional) Arbitrary indirection-free metadata for
Expand Down
3 changes: 3 additions & 0 deletions mongoengine/mongodb_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
MONGODB_36 = (3, 6)
MONGODB_42 = (4, 2)
MONGODB_44 = (4, 4)
MONGODB_50 = (5, 0)
MONGODB_60 = (6, 0)
MONGODB_70 = (7, 0)


def get_mongodb_version():
Expand Down
92 changes: 70 additions & 22 deletions tests/document/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from mongoengine.connection import get_db
from mongoengine.mongodb_support import (
MONGODB_42,
MONGODB_70,
get_mongodb_version,
)
from mongoengine.pymongo_support import PYMONGO_VERSION
Expand Down Expand Up @@ -466,30 +467,73 @@ class Test(Document):
== "IDHACK"
)

query_plan = Test.objects(a=1).only("a").exclude("id").explain()
assert (
query_plan.get("queryPlanner")
.get("winningPlan")
.get("inputStage")
.get("stage")
== "IXSCAN"
)
mongo_db = get_mongodb_version()
query_plan = Test.objects(a=1).only("a").exclude("id").explain()
if mongo_db < MONGODB_70:
assert (
query_plan.get("queryPlanner")
.get("winningPlan")
.get("inputStage")
.get("stage")
== "IXSCAN"
)
else:
assert (
query_plan.get("queryPlanner")
.get("winningPlan")
.get("queryPlan")
.get("inputStage")
.get("stage")
== "IXSCAN"
)

PROJECTION_STR = "PROJECTION" if mongo_db < MONGODB_42 else "PROJECTION_COVERED"
assert (
query_plan.get("queryPlanner").get("winningPlan").get("stage")
== PROJECTION_STR
)
if mongo_db < MONGODB_70:
assert (
query_plan.get("queryPlanner").get("winningPlan").get("stage")
== PROJECTION_STR
)
else:
assert (
query_plan.get("queryPlanner")
.get("winningPlan")
.get("queryPlan")
.get("stage")
== PROJECTION_STR
)

query_plan = Test.objects(a=1).explain()
assert (
query_plan.get("queryPlanner")
.get("winningPlan")
.get("inputStage")
.get("stage")
== "IXSCAN"
)
assert query_plan.get("queryPlanner").get("winningPlan").get("stage") == "FETCH"
if mongo_db < MONGODB_70:
assert (
query_plan.get("queryPlanner")
.get("winningPlan")
.get("inputStage")
.get("stage")
== "IXSCAN"
)
else:
assert (
query_plan.get("queryPlanner")
.get("winningPlan")
.get("queryPlan")
.get("inputStage")
.get("stage")
== "IXSCAN"
)

if mongo_db < MONGODB_70:
assert (
query_plan.get("queryPlanner").get("winningPlan").get("stage")
== "FETCH"
)
else:
assert (
query_plan.get("queryPlanner")
.get("winningPlan")
.get("queryPlan")
.get("stage")
== "FETCH"
)

def test_index_on_id(self):
class BlogPost(Document):
Expand Down Expand Up @@ -536,8 +580,12 @@ class BlogPost(Document):
BlogPost.objects.hint("Bad Name").count()

# Invalid shape argument (missing list brackets) should fail.
with pytest.raises(ValueError):
BlogPost.objects.hint(("tags", 1)).count()
if PYMONGO_VERSION <= (4, 3):
with pytest.raises(ValueError):
BlogPost.objects.hint(("tags", 1)).count()
else:
with pytest.raises(TypeError):
BlogPost.objects.hint(("tags", 1)).count()

def test_collation(self):
base = {"locale": "en", "strength": 2}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dereference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,8 +1116,8 @@ class Baz(Document):
foo.save()
foo.reload()

assert type(foo.bar) == Bar
assert type(foo.baz) == Baz
assert isinstance(foo.bar, Bar)
assert isinstance(foo.baz, Baz)

def test_document_reload_reference_integrity(self):
"""
Expand Down
4 changes: 3 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}
envlist = pypy3-{mg34,mg36,mg39,mg311,mg312,mg4,mg432,mg441,mg460}

[testenv]
commands =
Expand All @@ -12,5 +12,7 @@ deps =
mg312: pymongo>=3.12,<3.13
mg4: pymongo>=4.0,<4.1
mg432: pymongo>=4.3,<4.4
mg441: pymongo>=4.4,<4.5
mg460: pymongo>=4.6,<4.7
setenv =
PYTHON_EGG_CACHE = {envdir}/python-eggs

0 comments on commit b7617bb

Please sign in to comment.