Skip to content

Commit 5827580

Browse files
committed
More clean ups.
1 parent b8baa4e commit 5827580

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

django_mongodb_backend/fields/json.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ def data_contains(self, compiler, connection, as_path=False): # noqa: ARG001
5454
def _has_key_predicate(path, root_column=None, negated=False, as_path=False):
5555
"""Return MQL to check for the existence of `path`."""
5656
if as_path:
57-
# if not negated:
5857
return {path: {"$exists": not negated}}
59-
# return {"$and": [{path: {"$exists": True}}, {path: {"$ne": None}}]}
60-
# return {"$or": [{path: {"$exists": False}}, {path: None}]}
6158
result = {
6259
"$and": [
6360
# The path must exist (i.e. not be "missing").

django_mongodb_backend/functions.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
def cast(self, compiler, connection):
6969
output_type = connection.data_types[self.output_field.get_internal_type()]
70-
lhs_mql = process_lhs(self, compiler, connection, as_path=False)[0]
70+
lhs_mql = process_lhs(self, compiler, connection)[0]
7171
if max_length := self.output_field.max_length:
7272
lhs_mql = {"$substrCP": [lhs_mql, 0, max_length]}
7373
# Skip the conversion for "object" as it doesn't need to be transformed for
@@ -81,7 +81,7 @@ def cast(self, compiler, connection):
8181

8282

8383
def concat(self, compiler, connection):
84-
return self.get_source_expressions()[0].as_mql(compiler, connection, as_path=False)
84+
return self.get_source_expressions()[0].as_mql(compiler, connection)
8585

8686

8787
def concat_pair(self, compiler, connection):
@@ -91,12 +91,12 @@ def concat_pair(self, compiler, connection):
9191

9292

9393
def cot(self, compiler, connection):
94-
lhs_mql = process_lhs(self, compiler, connection, as_path=False)
94+
lhs_mql = process_lhs(self, compiler, connection)
9595
return {"$divide": [1, {"$tan": lhs_mql}]}
9696

9797

98-
def extract(self, compiler, connection, as_path=False):
99-
lhs_mql = process_lhs(self, compiler, connection, as_path=as_path)
98+
def extract(self, compiler, connection):
99+
lhs_mql = process_lhs(self, compiler, connection)
100100
operator = EXTRACT_OPERATORS.get(self.lookup_name)
101101
if operator is None:
102102
raise NotSupportedError(f"{self.__class__.__name__} is not supported.")
@@ -105,22 +105,8 @@ def extract(self, compiler, connection, as_path=False):
105105
return {f"${operator}": lhs_mql}
106106

107107

108-
def func(self, compiler, connection, as_path=False):
109-
lhs_mql = process_lhs(self, compiler, connection, as_path=False)
110-
if self.function is None:
111-
raise NotSupportedError(f"{self} may need an as_mql() method.")
112-
operator = MONGO_OPERATORS.get(self.__class__, self.function.lower())
113-
if as_path:
114-
return {"$expr": {f"${operator}": lhs_mql}}
115-
return {f"${operator}": lhs_mql}
116-
117-
118-
def func_path(self, compiler, connection): # noqa: ARG001
119-
raise NotSupportedError(f"{self} may need an as_mql_path() method.")
120-
121-
122-
def func_expr(self, compiler, connection):
123-
lhs_mql = process_lhs(self, compiler, connection, as_path=False)
108+
def func(self, compiler, connection):
109+
lhs_mql = process_lhs(self, compiler, connection)
124110
if self.function is None:
125111
raise NotSupportedError(f"{self} may need an as_mql() method.")
126112
operator = MONGO_OPERATORS.get(self.__class__, self.function.lower())
@@ -291,8 +277,8 @@ def register_functions():
291277
ConcatPair.as_mql_expr = concat_pair
292278
Cot.as_mql_expr = cot
293279
Extract.as_mql_expr = extract
294-
Func.as_mql_path = func_path
295-
Func.as_mql_expr = func_expr
280+
Func.as_mql_expr = func
281+
Func.can_use_path = False
296282
JSONArray.as_mql_expr = process_lhs
297283
Left.as_mql_expr = left
298284
Length.as_mql_expr = length
@@ -312,4 +298,3 @@ def register_functions():
312298
TruncDate.as_mql_expr = trunc_date
313299
TruncTime.as_mql_expr = trunc_time
314300
Upper.as_mql_expr = preserve_null("toUpper")
315-
Func.can_use_path = False

0 commit comments

Comments
 (0)