@@ -107,11 +107,19 @@ def key_transform(self, compiler, connection):
107
107
return result
108
108
109
109
110
+ def _expr_type_in (mql , types , negation = False ):
111
+ result = {"$in" : [{"$type" : mql }, types ]}
112
+ if negation :
113
+ result = {"$not" : result }
114
+ return result
115
+
116
+
110
117
def key_transform_in (self , compiler , connection ):
111
118
lhs_mql = process_lhs (self , compiler , connection )
112
119
value = process_rhs (self , compiler , connection )
113
120
expr = connection .mongo_operators [self .lookup_name ](lhs_mql , value )
114
- return {"$and" : [expr , {"$not" : {"$in" : [{"$type" : lhs_mql }, ["missing" , "null" ]]}}]}
121
+ type_in = _expr_type_in (lhs_mql , ["missing" , "null" ], True )
122
+ return {"$and" : [expr , type_in ]}
115
123
116
124
117
125
def key_transform_isnull (self , compiler , connection ):
@@ -123,8 +131,8 @@ def key_transform_isnull(self, compiler, connection):
123
131
lhs_mql = process_lhs (self , compiler , connection )
124
132
rhs_mql = process_rhs (self , compiler , connection )
125
133
root_column = _key_transform_root (self , compiler , connection )
126
-
127
- result = {"$or" : [{ "$in" : [{ "$type" : lhs_mql }, [ "missing" ]]} , {"$eq" : [root_column , None ]}]}
134
+ type_in = _expr_type_in ( lhs_mql , [ "missing" ])
135
+ result = {"$or" : [type_in , {"$eq" : [root_column , None ]}]}
128
136
if not rhs_mql :
129
137
result = {"$not" : result }
130
138
return result
@@ -133,7 +141,8 @@ def key_transform_isnull(self, compiler, connection):
133
141
def key_transform_numeric_lookup_mixin (self , compiler , connection ):
134
142
expr = builtin_lookup (self , compiler , connection )
135
143
lhs = process_lhs (self , compiler , connection )
136
- return {"$and" : [expr , {"$not" : {"$in" : [{"$type" : lhs }, ["missing" , "null" ]]}}]}
144
+ type_in = _expr_type_in (lhs , ["missing" , "null" ], True )
145
+ return {"$and" : [expr , type_in ]}
137
146
138
147
139
148
def register_fields ():
0 commit comments