3333from ..query_utils import is_direct_value , process_lhs
3434
3535
36- # EXTRA IS TOTALLY IGNORED
37- # shall check if we could optimize match here
3836def case (self , compiler , connection , as_path = False ):
3937 case_parts = []
4038 for case in self .cases :
@@ -94,21 +92,20 @@ def col_pairs(self, compiler, connection, as_path=False):
9492 return cols [0 ].as_mql (compiler , connection , as_path = as_path )
9593
9694
97- def combined_expression (self , compiler , connection , ** extra ):
95+ def combined_expression (self , compiler , connection , as_path = False ):
9896 expressions = [
99- self .lhs .as_mql (compiler , connection , ** extra ),
100- self .rhs .as_mql (compiler , connection , ** extra ),
97+ self .lhs .as_mql (compiler , connection , as_path = as_path ),
98+ self .rhs .as_mql (compiler , connection , as_path = as_path ),
10199 ]
102100 return connection .ops .combine_expression (self .connector , expressions )
103101
104102
105- def expression_wrapper (self , compiler , connection , ** extra ):
106- return self .expression .as_mql (compiler , connection , ** extra )
103+ def expression_wrapper (self , compiler , connection , as_path = False ):
104+ return self .expression .as_mql (compiler , connection , as_path = as_path )
107105
108106
109- def negated_expression (self , compiler , connection , ** extra ):
110- # review
111- return {"$not" : expression_wrapper (self , compiler , connection , ** extra )}
107+ def negated_expression (self , compiler , connection , as_path = False ):
108+ return {"$not" : expression_wrapper (self , compiler , connection , as_path = as_path )}
112109
113110
114111def order_by (self , compiler , connection ):
@@ -194,15 +191,14 @@ def subquery(self, compiler, connection, get_wrapping_pipeline=None, as_path=Fal
194191 return expr
195192
196193
197- def exists (self , compiler , connection , get_wrapping_pipeline = None , as_path = False , ** extra ):
194+ def exists (self , compiler , connection , get_wrapping_pipeline = None , as_path = False ):
198195 try :
199196 lhs_mql = subquery (
200197 self ,
201198 compiler ,
202199 connection ,
203200 get_wrapping_pipeline = get_wrapping_pipeline ,
204201 as_path = as_path ,
205- ** extra ,
206202 )
207203 except EmptyResultSet :
208204 return Value (False ).as_mql (compiler , connection )
@@ -211,8 +207,8 @@ def exists(self, compiler, connection, get_wrapping_pipeline=None, as_path=False
211207 return connection .mongo_operators_expr ["isnull" ](lhs_mql , False )
212208
213209
214- def when (self , compiler , connection , ** extra ):
215- return self .condition .as_mql (compiler , connection , ** extra )
210+ def when (self , compiler , connection , as_path = False ):
211+ return self .condition .as_mql (compiler , connection , as_path = as_path )
216212
217213
218214def value (self , compiler , connection , as_path = False ): # noqa: ARG001
@@ -244,9 +240,8 @@ def _is_constant_value(value):
244240 if isinstance (value , list | Array ):
245241 iterable = value .get_source_expressions () if isinstance (value , Array ) else value
246242 return all (_is_constant_value (e ) for e in iterable )
247- if isinstance (value , Value ) or is_direct_value (value ):
248- v = value .value if isinstance (value , Value ) else value
249- return not isinstance (v , str ) or "." not in v
243+ if is_direct_value (value ):
244+ return True
250245 return isinstance (value , Func | Value ) and not (
251246 value .contains_aggregate
252247 or value .contains_over_clause
@@ -266,7 +261,7 @@ def _is_simple_column(lhs):
266261 return isinstance (col , Col ) and col .alias is not None
267262
268263
269- def is_simple_expression (self ):
264+ def _is_simple_expression (self ):
270265 return self .is_simple_column (self .lhs ) and self .is_constant_value (self .rhs )
271266
272267
@@ -288,6 +283,6 @@ def register_expressions():
288283 Subquery .as_mql = subquery
289284 When .as_mql = when
290285 Value .as_mql = value
291- BaseExpression .is_simple_expression = is_simple_expression
286+ BaseExpression .is_simple_expression = _is_simple_expression
292287 BaseExpression .is_simple_column = _is_simple_column
293288 BaseExpression .is_constant_value = _is_constant_value
0 commit comments