@@ -72,7 +72,7 @@ def test_eq_and_in(self):
7272
7373class NullValueLookupTests (MongoTestCaseMixin , TestCase ):
7474 _OPERATOR_PREDICATE_MAP = {
75- "eq " : lambda field : {field : None },
75+ "exact " : lambda field : {field : None },
7676 "in" : lambda field : {field : {"$in" : [None ]}},
7777 }
7878
@@ -89,7 +89,9 @@ def setUpTestData(cls):
8989 def _test_none_filter_nullable_json (self , op , predicate , field ):
9090 with self .assertNumQueries (1 ) as ctx :
9191 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+ ),
9395 [],
9496 )
9597 self .assertAggregateQuery (
@@ -100,7 +102,9 @@ def _test_none_filter_nullable_json(self, op, predicate, field):
100102
101103 def _test_none_filter_binary_operator (self , op , predicate , field ):
102104 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+ )
104108 self .assertAggregateQuery (
105109 ctx .captured_queries [0 ]["sql" ],
106110 "lookup__book" ,
@@ -116,20 +120,20 @@ def _test_none_filter_binary_operator(self, op, predicate, field):
116120 ],
117121 )
118122
119- def _test_with_raw_data (self , model , test_function ):
123+ def _test_with_raw_data (self , model , test_function , field ):
120124 collection = connection .database .get_collection (model ._meta .db_table )
121125 try :
122126 collection .insert_one ({"_id" : self .unique_id })
123127
124128 for op , predicate in self ._OPERATOR_PREDICATE_MAP .items ():
125129 with self .subTest (op = op ):
126- test_function (op , predicate , "title" )
130+ test_function (op , predicate , field )
127131
128132 finally :
129133 collection .delete_one ({"_id" : self .unique_id })
130134
131135 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" )
133137
134138 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