diff --git a/ami/main/api/views.py b/ami/main/api/views.py index a7f4a8756..87b4aa919 100644 --- a/ami/main/api/views.py +++ b/ami/main/api/views.py @@ -434,7 +434,8 @@ class OccurrenceViewSet(DefaultViewSet): """ queryset = ( - Occurrence.objects.exclude(detections=None) # This must come before annotations + Occurrence.objects.exclude(detections=None) + .exclude(event=None) # These must be independent exclude calls .annotate( detections_count=models.Count("detections", distinct=True), duration=models.Max("detections__timestamp") - models.Min("detections__timestamp"), @@ -447,7 +448,7 @@ class OccurrenceViewSet(DefaultViewSet): ) .prefetch_related("detections") .order_by("-determination_score") - .exclude(event=None, first_appearance_time=None) # These must come after annotations + .exclude(first_appearance_time=None) # This must come after annotations ) serializer_class = OccurrenceSerializer filterset_fields = ["event", "deployment", "determination", "project"]