From 2123496953061c9f6a770ed303a9330ede2c1d0c Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Tue, 29 Oct 2024 13:03:24 -0400 Subject: [PATCH] fix: wrong search count for some searches across nested properties --- chord_metadata_service/discovery/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/chord_metadata_service/discovery/utils.py b/chord_metadata_service/discovery/utils.py index d5647f35a..df6dc13ea 100644 --- a/chord_metadata_service/discovery/utils.py +++ b/chord_metadata_service/discovery/utils.py @@ -242,9 +242,14 @@ def get_public_model_scoped_queryset(scope: ValidatedDiscoveryScope, mn: PublicM filter_scope = "project" value = scope.project_id else: - return PUBLIC_MODEL_NAMES_TO_MODEL[mn].objects.all() + return PUBLIC_MODEL_NAMES_TO_MODEL[mn].objects.distinct() filter_query = PUBLIC_MODEL_NAMES_TO_SCOPE_FILTERS[mn][filter_scope]["filter"] prefetch = PUBLIC_MODEL_NAMES_TO_SCOPE_FILTERS[mn][filter_scope]["prefetch_related"] - return PUBLIC_MODEL_NAMES_TO_MODEL[mn].objects.prefetch_related(*prefetch).filter(**{filter_query: value}) + return ( + PUBLIC_MODEL_NAMES_TO_MODEL[mn].objects + .distinct() + .prefetch_related(*prefetch) + .filter(**{filter_query: value}) + )