Skip to content

Commit fa72e1c

Browse files
committed
Fix for mongo 6.
1 parent a78f26b commit fa72e1c

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

django_mongodb_backend/expressions/builtins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030

3131
# EXTRA IS TOTALLY IGNORED
32+
# shall check if we could optimize match here
3233
def case(self, compiler, connection, **extra): # noqa: ARG001
3334
case_parts = []
3435
for case in self.cases:

django_mongodb_backend/functions.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,18 @@ def wrapped(self, compiler, connection, as_path=False):
157157
lhs_mql = process_lhs(self, compiler, connection, as_path=True)
158158
return lhs_mql.upper()
159159
lhs_mql = process_lhs(self, compiler, connection, as_path=False)
160-
return {
161-
"$expr": {
162-
"$cond": {
163-
"if": connection.mongo_operators_expr["isnull"](lhs_mql, True),
164-
"then": None,
165-
"else": {f"${operator}": lhs_mql},
166-
}
160+
inner_expression = {
161+
"$cond": {
162+
"if": connection.mongo_operators_expr["isnull"](lhs_mql, True),
163+
"then": None,
164+
"else": {f"${operator}": lhs_mql},
167165
}
168166
}
167+
# we need to wrap this, because it will be handled in a no expression tree.
168+
# needed in MongoDB 6.
169+
if as_path:
170+
return {"$expr": inner_expression}
171+
return inner_expression
169172

170173
return wrapped
171174

django_mongodb_backend/lookups.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def builtin_lookup(self, compiler, connection, as_path=False):
4848

4949
value = process_rhs(self, compiler, connection)
5050
lhs_mql = process_lhs(self, compiler, connection, as_path=False)
51-
return {"$expr": connection.mongo_operators_expr[self.lookup_name](lhs_mql, value)}
51+
if as_path:
52+
return {"$expr": connection.mongo_operators_expr[self.lookup_name](lhs_mql, value)}
53+
return connection.mongo_operators_expr[self.lookup_name](lhs_mql, value)
5254

5355

5456
_field_resolve_expression_parameter = FieldGetDbPrepValueIterableMixin.resolve_expression_parameter
@@ -116,7 +118,9 @@ def is_null(self, compiler, connection, as_path=False):
116118
lhs_mql = process_lhs(self, compiler, connection, as_path=as_path)
117119
return connection.mongo_operators_match["isnull"](lhs_mql, self.rhs)
118120
lhs_mql = process_lhs(self, compiler, connection, as_path=False)
119-
return {"$expr": connection.mongo_operators_expr["isnull"](lhs_mql, self.rhs)}
121+
if as_path:
122+
return {"$expr": connection.mongo_operators_expr["isnull"](lhs_mql, self.rhs)}
123+
return connection.mongo_operators_expr["isnull"](lhs_mql, self.rhs)
120124

121125

122126
# from https://www.pcre.org/current/doc/html/pcre2pattern.html#SEC4

0 commit comments

Comments
 (0)