Skip to content

Commit ed9d2f7

Browse files
authored
Merge branch 'master' into __raw__and_mongoengine
2 parents c8607d5 + cfb4265 commit ed9d2f7

File tree

17 files changed

+231
-80
lines changed

17 files changed

+231
-80
lines changed

.github/workflows/github-actions.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ env:
1717
MONGODB_4_0: 4.0.28
1818
MONGODB_4_4: 4.4
1919
MONGODB_5_0: "5.0"
20+
MONGODB_6_0: "6.0"
21+
MONGODB_7_0: "7.0"
2022

2123
PYMONGO_3_4: 3.4
2224
PYMONGO_3_6: 3.6
@@ -25,6 +27,8 @@ env:
2527
PYMONGO_3_12: 3.12
2628
PYMONGO_4_0: 4.0
2729
PYMONGO_4_3: 4.3.2
30+
PYMONGO_4_4: 4.4.1
31+
PYMONGO_4_6: 4.6.0
2832

2933
MAIN_PYTHON_VERSION: 3.7
3034

@@ -68,6 +72,12 @@ jobs:
6872
- python-version: "3.11"
6973
MONGODB: $MONGODB_5_0
7074
PYMONGO: $PYMONGO_4_3
75+
- python-version: "3.11"
76+
MONGODB: $MONGODB_6_0
77+
PYMONGO: $PYMONGO_4_4
78+
- python-version: "3.11"
79+
MONGODB: $MONGODB_7_0
80+
PYMONGO: $PYMONGO_4_6
7181
steps:
7282
- uses: actions/checkout@v3
7383
- name: Set up Python ${{ matrix.python-version }}

.github/workflows/install_mongo.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ elif [[ "$MONGODB" == *"4.4"* ]]; then
1111
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
1212
elif [[ "$MONGODB" == *"5.0"* ]]; then
1313
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
14+
elif [[ "$MONGODB" == *"6.0"* ]]; then
15+
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
16+
elif [[ "$MONGODB" == *"7.0"* ]]; then
17+
mongo_build=mongodb-linux-x86_64-ubuntu2004-v${MONGODB}-latest
1418
fi
1519

1620
wget http://fastdl.mongodb.org/linux/$mongo_build.tgz

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ an `API reference <https://mongoengine-odm.readthedocs.io/apireference.html>`_.
3131

3232
Supported MongoDB Versions
3333
==========================
34-
MongoEngine is currently tested against MongoDB v3.6, v4.0, v4.4 and v5.0. Future versions
34+
MongoEngine is currently tested against MongoDB v3.6, v4.0, v4.4, v5.0, v6.0 and v7.0. Future versions
3535
should be supported as well, but aren't actively tested at the moment. Make
3636
sure to open an issue or submit a pull request if you experience any problems
3737
with a more recent MongoDB versions.

docs/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ Development
99
- (Fill this out as you fix issues and develop your features).
1010
- Fix for uuidRepresentation not read when provided in URI #2741
1111
- Fix combination of __raw__ and mongoengine syntax.
12+
- Add tests against MongoDB 6.0 and MongoDB 7.0 in the pipeline
13+
- Fix validate() not being called when inheritance is used in EmbeddedDocument and validate is overriden #2784
14+
- Add support for readPreferenceTags in connection parameters #2644
15+
- Use estimated_documents_count OR documents_count when count is called, based on the query #2529
16+
- Fix no_dereference context manager which wasn't turning off auto-dereferencing correctly in some cases #2788
17+
- BREAKING CHANGE: no_dereference context manager no longer returns the class in __enter__ #2788
18+
as it was useless and making it look like it was returning a different class although it was the same.
19+
Thus, it must be called like `with no_dereference(User):` and no longer `with no_dereference(User) as ...:`
1220

1321
Changes in 0.27.0
1422
=================

docs/guide/querying.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ data. To turn off dereferencing of the results of a query use
522522
You can also turn off all dereferencing for a fixed period by using the
523523
:class:`~mongoengine.context_managers.no_dereference` context manager::
524524

525-
with no_dereference(Post) as Post:
525+
with no_dereference(Post):
526526
post = Post.objects.first()
527527
assert(isinstance(post.author, DBRef))
528528

mongoengine/base/fields.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ def __init__(
5959
unique with (Creates an index).
6060
:param primary_key: Mark this field as the primary key ((Creates an index)). Defaults to False.
6161
:param validation: (optional) A callable to validate the value of the
62-
field. The callable takes the value as parameter and should raise
62+
field. The callable takes the value as parameter and should raise
6363
a ValidationError if validation fails
6464
:param choices: (optional) The valid choices
65-
:param null: (optional) If the field value can be null when a default exist. If not set, the default value
66-
will be used in case a field with a default value is set to None. Defaults to False.
65+
:param null: (optional) If the field value can be null when a default exists. If not set, the default value
66+
will be used in case a field with a default value is set to None. Defaults to False.
6767
:param sparse: (optional) `sparse=True` combined with `unique=True` and `required=False`
6868
means that uniqueness won't be enforced for `None` values (Creates an index). Defaults to False.
6969
:param **kwargs: (optional) Arbitrary indirection-free metadata for

mongoengine/connection.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,16 @@ def _get_connection_settings(
164164
preference.name.lower() == read_pf_mode
165165
or preference.mode == read_pf_mode
166166
):
167-
conn_settings["read_preference"] = preference
167+
ReadPrefClass = preference.__class__
168168
break
169+
170+
if "readpreferencetags" in uri_options:
171+
conn_settings["read_preference"] = ReadPrefClass(
172+
tag_sets=uri_options["readpreferencetags"]
173+
)
174+
else:
175+
conn_settings["read_preference"] = ReadPrefClass()
176+
169177
if "authmechanismproperties" in uri_options:
170178
conn_settings["authmechanismproperties"] = uri_options[
171179
"authmechanismproperties"

mongoengine/context_managers.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import threading
12
from contextlib import contextmanager
23

34
from pymongo.read_concern import ReadConcern
@@ -18,6 +19,25 @@
1819
)
1920

2021

22+
thread_locals = threading.local()
23+
thread_locals.no_dereferencing_class = {}
24+
25+
26+
def no_dereferencing_active_for_class(cls):
27+
return cls in thread_locals.no_dereferencing_class
28+
29+
30+
def _register_no_dereferencing_for_class(cls):
31+
thread_locals.no_dereferencing_class.setdefault(cls, 0)
32+
thread_locals.no_dereferencing_class[cls] += 1
33+
34+
35+
def _unregister_no_dereferencing_for_class(cls):
36+
thread_locals.no_dereferencing_class[cls] -= 1
37+
if thread_locals.no_dereferencing_class[cls] == 0:
38+
thread_locals.no_dereferencing_class.pop(cls)
39+
40+
2141
class switch_db:
2242
"""switch_db alias context manager.
2343
@@ -107,7 +127,7 @@ class no_dereference:
107127
Turns off all dereferencing in Documents for the duration of the context
108128
manager::
109129
110-
with no_dereference(Group) as Group:
130+
with no_dereference(Group):
111131
Group.objects.find()
112132
"""
113133

@@ -130,15 +150,17 @@ def __init__(self, cls):
130150

131151
def __enter__(self):
132152
"""Change the objects default and _auto_dereference values."""
153+
_register_no_dereferencing_for_class(self.cls)
154+
133155
for field in self.deref_fields:
134156
self.cls._fields[field]._auto_dereference = False
135-
return self.cls
136157

137158
def __exit__(self, t, value, traceback):
138159
"""Reset the default and _auto_dereference values."""
160+
_unregister_no_dereferencing_for_class(self.cls)
161+
139162
for field in self.deref_fields:
140163
self.cls._fields[field]._auto_dereference = True
141-
return self.cls
142164

143165

144166
class no_sub_classes:

mongoengine/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ def validate(self, value, clean=True):
761761
"Invalid embedded document instance provided to an "
762762
"EmbeddedDocumentField"
763763
)
764-
self.document_type.validate(value, clean)
764+
value.validate(clean=clean)
765765

766766
def lookup_member(self, member_name):
767767
doc_and_subclasses = [self.document_type] + self.document_type.__subclasses__()

mongoengine/mongodb_support.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
MONGODB_36 = (3, 6)
1010
MONGODB_42 = (4, 2)
1111
MONGODB_44 = (4, 4)
12+
MONGODB_50 = (5, 0)
13+
MONGODB_60 = (6, 0)
14+
MONGODB_70 = (7, 0)
1215

1316

1417
def get_mongodb_version():

0 commit comments

Comments
 (0)