Fixed #24296 -- Made QuerySet.exists() clear selected columns for not sliced distinct querysets.
This commit is contained in:
parent
d2263b7b87
commit
0ad5316f22
|
@ -562,7 +562,7 @@ class Query(BaseExpression):
|
||||||
|
|
||||||
def exists(self, using, limit=True):
|
def exists(self, using, limit=True):
|
||||||
q = self.clone()
|
q = self.clone()
|
||||||
if not q.distinct:
|
if not (q.distinct and q.is_sliced):
|
||||||
if q.group_by is True:
|
if q.group_by is True:
|
||||||
q.add_fields(
|
q.add_fields(
|
||||||
(f.attname for f in self.model._meta.concrete_fields), False
|
(f.attname for f in self.model._meta.concrete_fields), False
|
||||||
|
|
|
@ -2226,6 +2226,14 @@ class ExistsSql(TestCase):
|
||||||
self.assertNotIn(id, qstr)
|
self.assertNotIn(id, qstr)
|
||||||
self.assertNotIn(name, qstr)
|
self.assertNotIn(name, qstr)
|
||||||
|
|
||||||
|
def test_distinct_exists(self):
|
||||||
|
with CaptureQueriesContext(connection) as captured_queries:
|
||||||
|
self.assertIs(Article.objects.distinct().exists(), False)
|
||||||
|
self.assertEqual(len(captured_queries), 1)
|
||||||
|
captured_sql = captured_queries[0]["sql"]
|
||||||
|
self.assertNotIn(connection.ops.quote_name("id"), captured_sql)
|
||||||
|
self.assertNotIn(connection.ops.quote_name("name"), captured_sql)
|
||||||
|
|
||||||
def test_sliced_distinct_exists(self):
|
def test_sliced_distinct_exists(self):
|
||||||
with CaptureQueriesContext(connection) as captured_queries:
|
with CaptureQueriesContext(connection) as captured_queries:
|
||||||
self.assertIs(Article.objects.distinct()[1:3].exists(), False)
|
self.assertIs(Article.objects.distinct()[1:3].exists(), False)
|
||||||
|
|
Loading…
Reference in New Issue