Skip to content

Commit 4d1cbac

Browse files
committed
edits
1 parent f074d96 commit 4d1cbac

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

django_mongodb/compiler.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,15 @@ def build_query(self, columns=None):
332332
"""Check if the query is supported and prepare a MongoQuery."""
333333
self.check_query()
334334
query = self.query_class(self)
335-
query.aggregation_pipeline = self.aggregation_pipeline
336335
query.lookup_pipeline = self.get_lookup_pipeline()
337336
query.order_by(self._get_ordering())
338337
query.project_fields = self.get_project_fields(columns, ordering=query.ordering)
339338
try:
340-
where = self.get_where()
341-
query.mongo_query = (
342-
{"$expr": where.as_mql(self, self.connection)} if where is not None else {}
343-
)
339+
expr = self.where.as_mql(self, self.connection) if self.where else {}
344340
except FullResultSet:
345341
query.mongo_query = {}
342+
else:
343+
query.mongo_query = {"$expr": expr}
346344
return query
347345

348346
def get_columns(self):
@@ -480,9 +478,6 @@ def get_project_fields(self, columns=None, ordering=None):
480478
fields[column] = 1
481479
return fields
482480

483-
def get_where(self):
484-
return self.where
485-
486481

487482
class SQLInsertCompiler(SQLCompiler):
488483
def execute_sql(self, returning_fields=None):
@@ -528,7 +523,8 @@ def check_query(self):
528523
"Cannot use QuerySet.delete() when querying across multiple collections on MongoDB."
529524
)
530525

531-
def get_where(self):
526+
@property
527+
def where(self):
532528
return self.query.where
533529

534530

@@ -592,15 +588,15 @@ def check_query(self):
592588
"Cannot use QuerySet.update() when querying across multiple collections on MongoDB."
593589
)
594590

595-
def get_where(self):
591+
@property
592+
def where(self):
596593
return self.query.where
597594

598595

599596
class SQLAggregateCompiler(SQLCompiler):
600597
def build_query(self, columns=None):
601598
query = self.query_class(self)
602599
query.project_fields = self.get_project_fields(tuple(self.annotations.items()))
603-
query.aggregation_pipeline = self.aggregation_pipeline
604600
compiler = self.query.inner_query.get_compiler(
605601
self.using,
606602
elide_empty=self.elide_empty,

django_mongodb/features.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
108108
"aggregation.tests.AggregateTestCase.test_aggregation_default_passed_another_aggregate",
109109
"aggregation.tests.AggregateTestCase.test_annotation_expressions",
110110
"aggregation.tests.AggregateTestCase.test_reverse_fkey_annotate",
111-
# Manage empty result when the flag elide_empty is False.
112-
"aggregation.tests.AggregateTestCase.test_empty_result_optimization",
113111
# Incorrect order: pipeline does not order by the correct fields.
114112
"aggregation.tests.AggregateTestCase.test_annotate_ordering",
115113
"aggregation.tests.AggregateTestCase.test_even_more_aggregate",
@@ -504,6 +502,7 @@ def django_test_expected_failures(self):
504502
"Custom aggregations/functions with SQL don't work on MongoDB.": {
505503
"aggregation.tests.AggregateTestCase.test_add_implementation",
506504
"aggregation.tests.AggregateTestCase.test_multi_arg_aggregate",
505+
"aggregation.tests.AggregateTestCase.test_empty_result_optimization",
507506
"annotations.tests.NonAggregateAnnotationTestCase.test_custom_functions",
508507
"annotations.tests.NonAggregateAnnotationTestCase.test_custom_functions_can_ref_other_functions",
509508
},

django_mongodb/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, compiler):
5050
self.subquery = None
5151
self.lookup_pipeline = None
5252
self.project_fields = None
53-
self.aggregation_pipeline = None
53+
self.aggregation_pipeline = compiler.aggregation_pipeline
5454

5555
def __repr__(self):
5656
return f"<MongoQuery: {self.mongo_query!r} ORDER {self.ordering!r}>"

0 commit comments

Comments
 (0)