Skip to content

Commit

Permalink
Fix filtering of occurrences without events
Browse files Browse the repository at this point in the history
  • Loading branch information
mihow authored and Debian committed Feb 3, 2024
1 parent e04ea5a commit 9e6bb42
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ami/main/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"]
Expand Down

0 comments on commit 9e6bb42

Please sign in to comment.