@@ -34,7 +34,7 @@ def case(self, compiler, connection, **extra): # noqa: ARG001
34
34
for case in self .cases :
35
35
case_mql = {}
36
36
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 )
38
38
except EmptyResultSet :
39
39
continue
40
40
except FullResultSet :
@@ -54,7 +54,7 @@ def case(self, compiler, connection, **extra): # noqa: ARG001
54
54
}
55
55
56
56
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
58
58
# If the column is part of a subquery and belongs to one of the parent
59
59
# queries, it will be stored for reference using $let in a $lookup stage.
60
60
# 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
72
72
# Add the column's collection's alias for columns in joined collections.
73
73
has_alias = self .alias and self .alias != compiler .collection_name
74
74
prefix = f"{ self .alias } ." if has_alias else ""
75
- if not as_path or as_expr :
75
+ if not as_path :
76
76
prefix = f"${ prefix } "
77
77
return f"{ prefix } { self .target .column } "
78
78
79
79
80
- def col_pairs (self , compiler , connection ):
80
+ def col_pairs (self , compiler , connection , as_path = False ):
81
81
cols = self .get_cols ()
82
82
if len (cols ) > 1 :
83
83
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 )
85
85
86
86
87
87
def combined_expression (self , compiler , connection , ** extra ):
@@ -96,15 +96,15 @@ def expression_wrapper(self, compiler, connection, **extra):
96
96
return self .expression .as_mql (compiler , connection , ** extra )
97
97
98
98
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 )}
101
101
102
102
103
103
def order_by (self , compiler , connection ):
104
104
return self .expression .as_mql (compiler , connection )
105
105
106
106
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 ):
108
108
subquery_compiler = self .get_compiler (connection = connection )
109
109
subquery_compiler .pre_sql_setup (with_col_aliases = False )
110
110
field_name , expr = subquery_compiler .columns [0 ]
@@ -146,7 +146,7 @@ def query(self, compiler, connection, get_wrapping_pipeline=None, as_path=False,
146
146
# Erase project_fields since the required value is projected above.
147
147
subquery .project_fields = None
148
148
compiler .subqueries .append (subquery )
149
- if as_path and not as_expr :
149
+ if as_path :
150
150
return f"{ table_output } .{ field_name } "
151
151
return f"${ table_output } .{ field_name } "
152
152
@@ -201,8 +201,10 @@ def when(self, compiler, connection, **extra):
201
201
return self .condition .as_mql (compiler , connection , ** extra )
202
202
203
203
204
- def value (self , compiler , connection , ** extra ): # noqa: ARG001
204
+ def value (self , compiler , connection , as_path = False ): # noqa: ARG001
205
205
value = self .value
206
+ if as_path :
207
+ return value
206
208
if isinstance (value , (list , int )):
207
209
# Wrap lists & numbers in $literal to prevent ambiguity when Value
208
210
# appears in $project.
0 commit comments