@@ -34,7 +34,7 @@ def case(self, compiler, connection, **extra): # noqa: ARG001
3434 for case in self .cases :
3535 case_mql = {}
3636 try :
37- case_mql ["case" ] = case .as_mql (compiler , connection , as_expr = True )
37+ case_mql ["case" ] = case .as_mql (compiler , connection , as_path = False )
3838 except EmptyResultSet :
3939 continue
4040 except FullResultSet :
@@ -54,7 +54,7 @@ def case(self, compiler, connection, **extra): # noqa: ARG001
5454 }
5555
5656
57- def col (self , compiler , connection , as_path = False , as_expr = None ): # noqa: ARG001
57+ def col (self , compiler , connection , as_path = False ): # noqa: ARG001
5858 # If the column is part of a subquery and belongs to one of the parent
5959 # queries, it will be stored for reference using $let in a $lookup stage.
6060 # If the query is built with `alias_cols=False`, treat the column as
@@ -72,16 +72,16 @@ def col(self, compiler, connection, as_path=False, as_expr=None): # noqa: ARG00
7272 # Add the column's collection's alias for columns in joined collections.
7373 has_alias = self .alias and self .alias != compiler .collection_name
7474 prefix = f"{ self .alias } ." if has_alias else ""
75- if not as_path or as_expr :
75+ if not as_path :
7676 prefix = f"${ prefix } "
7777 return f"{ prefix } { self .target .column } "
7878
7979
80- def col_pairs (self , compiler , connection ):
80+ def col_pairs (self , compiler , connection , as_path = False ):
8181 cols = self .get_cols ()
8282 if len (cols ) > 1 :
8383 raise NotSupportedError ("ColPairs is not supported." )
84- return cols [0 ].as_mql (compiler , connection )
84+ return cols [0 ].as_mql (compiler , connection , as_path = as_path )
8585
8686
8787def combined_expression (self , compiler , connection , ** extra ):
@@ -96,15 +96,15 @@ def expression_wrapper(self, compiler, connection, **extra):
9696 return self .expression .as_mql (compiler , connection , ** extra )
9797
9898
99- def negated_expression (self , compiler , connection ):
100- return {"$not" : expression_wrapper (self , compiler , connection )}
99+ def negated_expression (self , compiler , connection , ** extra ):
100+ return {"$not" : expression_wrapper (self , compiler , connection , ** extra )}
101101
102102
103103def order_by (self , compiler , connection ):
104104 return self .expression .as_mql (compiler , connection )
105105
106106
107- def query (self , compiler , connection , get_wrapping_pipeline = None , as_path = False , as_expr = None ):
107+ def query (self , compiler , connection , get_wrapping_pipeline = None , as_path = False ):
108108 subquery_compiler = self .get_compiler (connection = connection )
109109 subquery_compiler .pre_sql_setup (with_col_aliases = False )
110110 field_name , expr = subquery_compiler .columns [0 ]
@@ -146,7 +146,7 @@ def query(self, compiler, connection, get_wrapping_pipeline=None, as_path=False,
146146 # Erase project_fields since the required value is projected above.
147147 subquery .project_fields = None
148148 compiler .subqueries .append (subquery )
149- if as_path and not as_expr :
149+ if as_path :
150150 return f"{ table_output } .{ field_name } "
151151 return f"${ table_output } .{ field_name } "
152152
@@ -201,8 +201,10 @@ def when(self, compiler, connection, **extra):
201201 return self .condition .as_mql (compiler , connection , ** extra )
202202
203203
204- def value (self , compiler , connection , ** extra ): # noqa: ARG001
204+ def value (self , compiler , connection , as_path = False ): # noqa: ARG001
205205 value = self .value
206+ if as_path :
207+ return value
206208 if isinstance (value , (list , int )):
207209 # Wrap lists & numbers in $literal to prevent ambiguity when Value
208210 # appears in $project.
0 commit comments