From 01a381cc17e6747e1d9e7b95a39e885029fd2a81 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Wed, 13 May 2020 14:44:10 +0200 Subject: [PATCH] Fixed #31580 -- Added error messages on distinct() following union(), intersection(), and difference(). --- django/db/models/query.py | 1 + tests/queries/test_qs_combinators.py | 1 + 2 files changed, 2 insertions(+) diff --git a/django/db/models/query.py b/django/db/models/query.py index e0eeccefa6..5c70229263 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -1138,6 +1138,7 @@ class QuerySet: """ Return a new QuerySet instance that will select only distinct results. """ + self._not_support_combined_queries('distinct') assert not self.query.is_sliced, \ "Cannot create distinct fields once a slice has been taken." obj = self._chain() diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py index 1d159e1fed..d2e7d2b80d 100644 --- a/tests/queries/test_qs_combinators.py +++ b/tests/queries/test_qs_combinators.py @@ -272,6 +272,7 @@ class QuerySetSetOperationTests(TestCase): 'annotate', 'defer', 'delete', + 'distinct', 'exclude', 'extra', 'filter',