From 1abba522b03fb854201c141c5e72e7281d6c94fc Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Tue, 24 May 2016 22:19:51 -0400 Subject: [PATCH] Resurrect global .distinct() call (mostly) This mostly reverts 3c67971e78a12bd94536aa5464f0bc1ea46ba1ee with the minor difference that we only apply this when we're filtering, which is apparently necessary without some notable overhaul since the filtering we're doing will get stuck in as filters, which will generate inner joins, which can result in duplicates if the thing we're joining with is a one to many or many to many, which most things are. With this patch we still need to be generating naturally distinct querysets with any `get_queryset` methods, which will still be much more effecient when filtering is not involved. This fixes #2032 and probably a bunch of other undiscovered issues. --- awx/api/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/api/filters.py b/awx/api/filters.py index d023b2aa08..f4e65a8d82 100644 --- a/awx/api/filters.py +++ b/awx/api/filters.py @@ -219,7 +219,7 @@ class FieldLookupBackend(BaseFilterBackend): else: q = Q(**{k:v}) queryset = queryset.filter(q) - queryset = queryset.filter(*args) + queryset = queryset.filter(*args).distinct() return queryset except (FieldError, FieldDoesNotExist, ValueError), e: raise ParseError(e.args[0])