Skip to content

Commit a26d2ff

Browse files
committed
add as_mql() fallback for generating annotations
as_mql_agg() only needs to be defined if it differs from as_mql()
1 parent 78fd337 commit a26d2ff

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

django_mongodb/functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def round_(self, compiler, connection):
5454

5555

5656
def register_functions():
57-
Cot.as_mql_agg = cot
57+
Cot.as_mql = cot
5858
Extract.as_mql = extract
59-
Func.as_mql_agg = func
60-
Log.as_mql_agg = log
61-
Round.as_mql_agg = round_
59+
Func.as_mql = func
60+
Log.as_mql = log
61+
Round.as_mql = round_

django_mongodb/query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def get_cursor(self):
9191
column = expr.target.column
9292
except AttributeError:
9393
# Generate the MQL for an annotation.
94-
fields[name] = expr.as_mql_agg(self.compiler, self.connection)
94+
method = 'as_mql_agg' if hasattr(expr, 'as_mql_agg') else 'as_mql'
95+
fields[name] = getattr(expr, method)(self.compiler, self.connection)
9596
else:
9697
# If name != column, then this is an annotatation referencing
9798
# another column.

0 commit comments

Comments
 (0)