@@ -251,7 +251,8 @@ def test_annotate(self):
251251 HasLinkThing .objects .create ()
252252 b = Board .objects .create (name = str (hs1 .pk ))
253253 Link .objects .create (content_object = hs2 )
254- link = Link .objects .create (content_object = hs1 )
254+ # An integer PK is required for the Sum() queryset that follows.
255+ link = Link .objects .create (content_object = hs1 , pk = 10 )
255256 Link .objects .create (content_object = b )
256257 qs = HasLinkThing .objects .annotate (Sum ("links" )).filter (pk = hs1 .pk )
257258 # If content_type restriction isn't in the query's join condition,
@@ -265,11 +266,11 @@ def test_annotate(self):
265266 # clear cached results
266267 qs = qs .all ()
267268 self .assertEqual (qs .count (), 1 )
268- # Note - 0 here would be a nicer result.. .
269- self .assertIs (qs [0 ].links__sum , None )
269+ # Unlike other databases, MongoDB returns 0 instead of null (None) .
270+ self .assertIs (qs [0 ].links__sum , 0 )
270271 # Finally test that filtering works.
271- self .assertEqual (qs .filter (links__sum__isnull = True ).count (), 1 )
272- self .assertEqual (qs .filter (links__sum__isnull = False ).count (), 0 )
272+ self .assertEqual (qs .filter (links__sum__isnull = True ).count (), 0 )
273+ self .assertEqual (qs .filter (links__sum__isnull = False ).count (), 1 )
273274
274275 def test_filter_targets_related_pk (self ):
275276 # Use hardcoded PKs to ensure different PKs for "link" and "hs2"
0 commit comments