7
7
from django_mongodb_backend .query_conversion .expression_converters import convert_expression
8
8
9
9
10
- def _wrap_condition_if_null (_type , condition ):
10
+ def _wrap_condition_if_null (_type , condition , path ):
11
11
if _type is None :
12
- return {"$and" : [{"$exists" : True }, condition ]}
12
+ return {"$and" : [{path : { "$exists" : True } }, condition ]}
13
13
return condition
14
14
15
15
@@ -104,12 +104,12 @@ def test_no_conversion_dict_value(self):
104
104
105
105
def _test_conversion_valid_type (self , _type ):
106
106
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" )
108
108
)
109
109
110
110
def _test_conversion_valid_array_type (self , _type ):
111
111
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" )
113
113
)
114
114
115
115
def test_conversion_various_types (self ):
@@ -265,7 +265,8 @@ def test_no_conversion_dict_value(self):
265
265
266
266
def _test_conversion_valid_type (self , _type ):
267
267
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" ),
269
270
)
270
271
271
272
def test_conversion_various_types (self ):
@@ -298,7 +299,7 @@ def test_no_conversion_dict_value(self):
298
299
def _test_conversion_valid_type (self , _type ):
299
300
expr = {"$gte" : ["$price" , _type ]}
300
301
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" ))
302
303
303
304
def test_conversion_various_types (self ):
304
305
self ._test_conversion_various_types (self ._test_conversion_valid_type )
@@ -325,7 +326,8 @@ def test_no_conversion_dict_value(self):
325
326
326
327
def _test_conversion_valid_type (self , _type ):
327
328
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" ),
329
331
)
330
332
331
333
def test_conversion_various_types (self ):
@@ -353,7 +355,8 @@ def test_no_conversion_dict_value(self):
353
355
354
356
def _test_conversion_valid_type (self , _type ):
355
357
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" ),
357
360
)
358
361
359
362
def test_conversion_various_types (self ):
0 commit comments