Skip to content

Commit b8baa4e

Browse files
committed
Clean ups.
1 parent a344004 commit b8baa4e

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

django_mongodb_backend/aggregates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ def count(self, compiler, connection, resolve_inner_expression=False, **extra_co
6464
return {"$add": [{"$size": lhs_mql}, exits_null]}
6565

6666

67-
def stddev_variance(self, compiler, connection, **extra_context): # noqa: ARG001
67+
def stddev_variance(self, compiler, connection, **extra_context):
6868
if self.function.endswith("_SAMP"):
6969
operator = "stdDevSamp"
7070
elif self.function.endswith("_POP"):
7171
operator = "stdDevPop"
72-
return aggregate(self, compiler, connection, operator=operator)
72+
return aggregate(self, compiler, connection, operator=operator, **extra_context)
7373

7474

7575
def register_aggregates():

django_mongodb_backend/compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,11 @@ def build_query(self, columns=None):
481481
query.lookup_pipeline = self.get_lookup_pipeline()
482482
where = self.get_where()
483483
try:
484-
expr = where.as_mql(self, self.connection, as_path=True) if where else {}
484+
match = where.as_mql(self, self.connection, as_path=True) if where else {}
485485
except FullResultSet:
486486
query.match_mql = {}
487487
else:
488-
query.match_mql = expr
488+
query.match_mql = match
489489
if extra_fields:
490490
query.extra_fields = self.get_project_fields(extra_fields, force_expression=True)
491491
query.subqueries = self.subqueries

django_mongodb_backend/expressions/builtins.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ def combined_expression(self, compiler, connection):
100100
return connection.ops.combine_expression(self.connector, expressions)
101101

102102

103-
def expression_wrapper_expr(self, compiler, connection):
103+
def expression_wrapper(self, compiler, connection):
104104
return self.expression.as_mql(compiler, connection)
105105

106106

107-
def negated_expression_expr(self, compiler, connection):
108-
return {"$not": expression_wrapper_expr(self, compiler, connection)}
107+
def negated_expression(self, compiler, connection):
108+
return {"$not": expression_wrapper(self, compiler, connection)}
109109

110110

111111
def order_by(self, compiler, connection):
@@ -201,8 +201,8 @@ def exists(self, compiler, connection, get_wrapping_pipeline=None):
201201
return connection.mongo_expr_operators["isnull"](lhs_mql, False)
202202

203203

204-
def when(self, compiler, connection, as_path=False):
205-
return self.condition.as_mql(compiler, connection, as_path=as_path)
204+
def when(self, compiler, connection):
205+
return self.condition.as_mql(compiler, connection)
206206

207207

208208
def value(self, compiler, connection, as_path=False): # noqa: ARG001
@@ -239,8 +239,8 @@ def register_expressions():
239239
CombinedExpression.as_mql_expr = combined_expression
240240
Exists.as_mql_expr = exists
241241
ExpressionList.as_mql = process_lhs
242-
ExpressionWrapper.as_mql_expr = expression_wrapper_expr
243-
NegatedExpression.as_mql_expr = negated_expression_expr
242+
ExpressionWrapper.as_mql_expr = expression_wrapper
243+
NegatedExpression.as_mql_expr = negated_expression
244244
OrderBy.as_mql_expr = order_by
245245
Query.as_mql = query
246246
RawSQL.as_mql = raw_sql
@@ -249,5 +249,5 @@ def register_expressions():
249249
ResolvedOuterRef.as_mql = ResolvedOuterRef.as_sql
250250
Star.as_mql_expr = star
251251
Subquery.as_mql_expr = subquery
252-
When.as_mql = when
252+
When.as_mql_expr = when
253253
Value.as_mql = value

django_mongodb_backend/functions.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,20 @@ def func_expr(self, compiler, connection):
128128

129129

130130
def left(self, compiler, connection):
131-
return self.get_substr().as_mql(compiler, connection, as_path=False)
131+
return self.get_substr().as_mql(compiler, connection)
132132

133133

134134
def length(self, compiler, connection):
135135
# Check for null first since $strLenCP only accepts strings.
136-
lhs_mql = process_lhs(self, compiler, connection, as_path=False)
136+
lhs_mql = process_lhs(self, compiler, connection)
137137
return {"$cond": {"if": {"$eq": [lhs_mql, None]}, "then": None, "else": {"$strLenCP": lhs_mql}}}
138138

139139

140140
def log(self, compiler, connection):
141141
# This function is usually log(base, num) but on MongoDB it's log(num, base).
142142
clone = self.copy()
143143
clone.set_source_expressions(self.get_source_expressions()[::-1])
144-
return func(clone, compiler, connection, as_path=False)
144+
return func(clone, compiler, connection)
145145

146146

147147
def now(self, compiler, connection): # noqa: ARG001
@@ -150,17 +150,15 @@ def now(self, compiler, connection): # noqa: ARG001
150150

151151
def null_if(self, compiler, connection):
152152
"""Return None if expr1==expr2 else expr1."""
153-
expr1, expr2 = (
154-
expr.as_mql(compiler, connection, as_path=False) for expr in self.get_source_expressions()
155-
)
153+
expr1, expr2 = (expr.as_mql(compiler, connection) for expr in self.get_source_expressions())
156154
return {"$cond": {"if": {"$eq": [expr1, expr2]}, "then": None, "else": expr1}}
157155

158156

159157
def preserve_null(operator):
160158
# If the argument is null, the function should return null, not
161159
# $toLower/Upper's behavior of returning an empty string.
162160
def wrapped(self, compiler, connection):
163-
lhs_mql = process_lhs(self, compiler, connection, as_path=False)
161+
lhs_mql = process_lhs(self, compiler, connection)
164162
return {
165163
"$cond": {
166164
"if": connection.mongo_expr_operators["isnull"](lhs_mql, True),
@@ -173,23 +171,18 @@ def wrapped(self, compiler, connection):
173171

174172

175173
def replace(self, compiler, connection):
176-
expression, text, replacement = process_lhs(self, compiler, connection, as_path=False)
174+
expression, text, replacement = process_lhs(self, compiler, connection)
177175
return {"$replaceAll": {"input": expression, "find": text, "replacement": replacement}}
178176

179177

180178
def round_(self, compiler, connection):
181179
# Round needs its own function because it's a special case that inherits
182180
# from Transform but has two arguments.
183-
return {
184-
"$round": [
185-
expr.as_mql(compiler, connection, as_path=False)
186-
for expr in self.get_source_expressions()
187-
]
188-
}
181+
return {"$round": [expr.as_mql(compiler, connection) for expr in self.get_source_expressions()]}
189182

190183

191184
def str_index(self, compiler, connection):
192-
lhs = process_lhs(self, compiler, connection, as_path=False)
185+
lhs = process_lhs(self, compiler, connection)
193186
# StrIndex should be 0-indexed (not found) but it's -1-indexed on MongoDB.
194187
return {"$add": [{"$indexOfCP": lhs}, 1]}
195188

@@ -253,7 +246,7 @@ def trunc_convert_value(self, value, expression, connection):
253246

254247
def trunc_date(self, compiler, connection):
255248
# Cast to date rather than truncate to date.
256-
lhs_mql = process_lhs(self, compiler, connection, as_path=False)
249+
lhs_mql = process_lhs(self, compiler, connection)
257250
tzname = self.get_tzname()
258251
if tzname and tzname != "UTC":
259252
raise NotSupportedError(f"TruncDate with tzinfo ({tzname}) isn't supported on MongoDB.")
@@ -276,7 +269,7 @@ def trunc_time(self, compiler, connection):
276269
tzname = self.get_tzname()
277270
if tzname and tzname != "UTC":
278271
raise NotSupportedError(f"TruncTime with tzinfo ({tzname}) isn't supported on MongoDB.")
279-
lhs_mql = process_lhs(self, compiler, connection, as_path=False)
272+
lhs_mql = process_lhs(self, compiler, connection)
280273
return {
281274
"$dateFromString": {
282275
"dateString": {

0 commit comments

Comments
 (0)