@@ -72,7 +72,7 @@ def test_eq_and_in(self):
72
72
73
73
class NullValueLookupTests (MongoTestCaseMixin , TestCase ):
74
74
_OPERATOR_PREDICATE_MAP = {
75
- "eq " : lambda field : {field : None },
75
+ "exact " : lambda field : {field : None },
76
76
"in" : lambda field : {field : {"$in" : [None ]}},
77
77
}
78
78
@@ -89,7 +89,9 @@ def setUpTestData(cls):
89
89
def _test_none_filter_nullable_json (self , op , predicate , field ):
90
90
with self .assertNumQueries (1 ) as ctx :
91
91
self .assertQuerySetEqual (
92
- NullableJSONModel .objects .filter (** {f"{ field } __{ op } " : None }),
92
+ NullableJSONModel .objects .filter (
93
+ ** {f"{ field } __{ op } " : [None ] if op == "in" else None }
94
+ ),
93
95
[],
94
96
)
95
97
self .assertAggregateQuery (
@@ -100,7 +102,9 @@ def _test_none_filter_nullable_json(self, op, predicate, field):
100
102
101
103
def _test_none_filter_binary_operator (self , op , predicate , field ):
102
104
with self .assertNumQueries (1 ) as ctx :
103
- self .assertQuerySetEqual (Book .objects .filter (** {f"{ field } __{ op } " : None }), [])
105
+ self .assertQuerySetEqual (
106
+ Book .objects .filter (** {f"{ field } __{ op } " : [None ] if op == "in" else None }), []
107
+ )
104
108
self .assertAggregateQuery (
105
109
ctx .captured_queries [0 ]["sql" ],
106
110
"lookup__book" ,
@@ -116,20 +120,20 @@ def _test_none_filter_binary_operator(self, op, predicate, field):
116
120
],
117
121
)
118
122
119
- def _test_with_raw_data (self , model , test_function ):
123
+ def _test_with_raw_data (self , model , test_function , field ):
120
124
collection = connection .database .get_collection (model ._meta .db_table )
121
125
try :
122
126
collection .insert_one ({"_id" : self .unique_id })
123
127
124
128
for op , predicate in self ._OPERATOR_PREDICATE_MAP .items ():
125
129
with self .subTest (op = op ):
126
- test_function (op , predicate , "title" )
130
+ test_function (op , predicate , field )
127
131
128
132
finally :
129
133
collection .delete_one ({"_id" : self .unique_id })
130
134
131
135
def test_none_filter_nullable_json (self ):
132
- self ._test_with_raw_data (NullableJSONModel , self ._test_none_filter_nullable_json )
136
+ self ._test_with_raw_data (NullableJSONModel , self ._test_none_filter_nullable_json , "value" )
133
137
134
138
def test_none_filter_binary_operator (self ):
135
- self ._test_with_raw_data (Book , self ._test_none_filter_binary_operator )
139
+ self ._test_with_raw_data (Book , self ._test_none_filter_binary_operator , "title" )
0 commit comments