77from django_mongodb_backend .query_conversion .expression_converters import convert_expression
88
99
10- def _wrap_condition_if_null (_type , condition ):
10+ def _wrap_condition_if_null (_type , condition , path ):
1111 if _type is None :
12- return {"$and" : [{"$exists" : True }, condition ]}
12+ return {"$and" : [{path : { "$exists" : True } }, condition ]}
1313 return condition
1414
1515
@@ -104,12 +104,12 @@ def test_no_conversion_dict_value(self):
104104
105105 def _test_conversion_valid_type (self , _type ):
106106 self .assertConversionEqual (
107- {"$eq" : ["$age" , _type ]}, _wrap_condition_if_null (_type , {"age" : _type })
107+ {"$eq" : ["$age" , _type ]}, _wrap_condition_if_null (_type , {"age" : _type }, "age" )
108108 )
109109
110110 def _test_conversion_valid_array_type (self , _type ):
111111 self .assertConversionEqual (
112- {"$eq" : ["$age" , _type ]}, _wrap_condition_if_null (_type , {"age" : _type })
112+ {"$eq" : ["$age" , _type ]}, _wrap_condition_if_null (_type , {"age" : _type }, "age" )
113113 )
114114
115115 def test_conversion_various_types (self ):
@@ -265,7 +265,8 @@ def test_no_conversion_dict_value(self):
265265
266266 def _test_conversion_valid_type (self , _type ):
267267 self .assertConversionEqual (
268- {"$gt" : ["$price" , _type ]}, _wrap_condition_if_null (_type , {"price" : {"$gt" : _type }})
268+ {"$gt" : ["$price" , _type ]},
269+ _wrap_condition_if_null (_type , {"price" : {"$gt" : _type }}, "price" ),
269270 )
270271
271272 def test_conversion_various_types (self ):
@@ -298,7 +299,7 @@ def test_no_conversion_dict_value(self):
298299 def _test_conversion_valid_type (self , _type ):
299300 expr = {"$gte" : ["$price" , _type ]}
300301 expected = {"price" : {"$gte" : _type }}
301- self .assertConversionEqual (expr , _wrap_condition_if_null (_type , expected ))
302+ self .assertConversionEqual (expr , _wrap_condition_if_null (_type , expected , "price" ))
302303
303304 def test_conversion_various_types (self ):
304305 self ._test_conversion_various_types (self ._test_conversion_valid_type )
@@ -325,7 +326,8 @@ def test_no_conversion_dict_value(self):
325326
326327 def _test_conversion_valid_type (self , _type ):
327328 self .assertConversionEqual (
328- {"$lt" : ["$price" , _type ]}, _wrap_condition_if_null (_type , {"price" : {"$lt" : _type }})
329+ {"$lt" : ["$price" , _type ]},
330+ _wrap_condition_if_null (_type , {"price" : {"$lt" : _type }}, "price" ),
329331 )
330332
331333 def test_conversion_various_types (self ):
@@ -353,7 +355,8 @@ def test_no_conversion_dict_value(self):
353355
354356 def _test_conversion_valid_type (self , _type ):
355357 self .assertConversionEqual (
356- {"$lte" : ["$price" , _type ]}, _wrap_condition_if_null (_type , {"price" : {"$lte" : _type }})
358+ {"$lte" : ["$price" , _type ]},
359+ _wrap_condition_if_null (_type , {"price" : {"$lte" : _type }}, "price" ),
357360 )
358361
359362 def test_conversion_various_types (self ):
0 commit comments