Skip to content

Commit e202054

Browse files
committed
Refactor.
1 parent a414d93 commit e202054

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

django_mongodb_backend/compiler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,7 @@ def get_combinator_queries(self):
643643
for alias, expr in self.columns:
644644
# Unfold foreign fields.
645645
if isinstance(expr, Col) and expr.alias != self.collection_name:
646-
ids[expr.alias][expr.target.column] = expr.as_mql(
647-
self, self.connection, as_path=False
648-
)
646+
ids[expr.alias][expr.target.column] = expr.as_mql(self, self.connection)
649647
else:
650648
ids[alias] = f"${alias}"
651649
# Convert defaultdict to dict so it doesn't appear as

django_mongodb_backend/lookups.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
UUIDTextMixin,
1010
)
1111

12-
from .query_utils import is_simple_expression, process_lhs, process_rhs
12+
from .query_utils import is_constant_value, process_lhs, process_rhs
1313

1414

1515
def builtin_lookup_path(self, compiler, connection):
@@ -138,6 +138,12 @@ def uuid_text_mixin(self, compiler, connection): # noqa: ARG001
138138
raise NotSupportedError("Pattern lookups on UUIDField are not supported.")
139139

140140

141+
def is_simple_expression(self):
142+
simple_column = getattr(self.lhs, "is_simple_column", False)
143+
constant_value = is_constant_value(self.rhs)
144+
return simple_column and constant_value
145+
146+
141147
def register_lookups():
142148
Lookup.is_simple_expression = is_simple_expression
143149
BuiltinLookup.as_mql_path = builtin_lookup_path

django_mongodb_backend/query.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def get_pipeline(self):
8888
pipeline.extend(query.get_pipeline())
8989
if self.match_mql:
9090
pipeline.append({"$match": self.match_mql})
91-
# pipeline.append({"$match": {"$expr": self.match_mql}})
9291
if self.aggregation_pipeline:
9392
pipeline.extend(self.aggregation_pipeline)
9493
if self.project_fields:
@@ -165,14 +164,13 @@ def _get_reroot_replacements(expression):
165164
for col, parent_pos in columns:
166165
target = col.target.clone()
167166
target.remote_field = col.target.remote_field
167+
column_target = Col(compiler.collection_name, target)
168168
if parent_pos is not None:
169-
column_target = Col(None, target)
170169
column_target.is_simple_column = False
171170
target_col = f"${parent_template}{parent_pos}"
172171
column_target.target.db_column = target_col
173172
column_target.target.set_attributes_from_name(target_col)
174173
else:
175-
column_target = Col(compiler.collection_name, target)
176174
column_target.target = col.target
177175
replacements[col] = column_target
178176
return replacements

django_mongodb_backend/query_utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,3 @@ def is_constant_value(value):
8989
or value.contains_subquery
9090
)
9191
)
92-
93-
94-
def is_simple_expression(self):
95-
simple_column = getattr(self.lhs, "is_simple_column", False)
96-
constant_value = is_constant_value(self.rhs)
97-
return simple_column and constant_value

0 commit comments

Comments
 (0)