summaryrefslogtreecommitdiff
path: root/tests/lookup
diff options
context:
space:
mode:
authorJames Timmins <jameshtimmins@gmail.com>2019-09-19 19:20:40 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-09-20 10:42:14 +0200
commit0719edcd5fed56157ffb3323a8f634aa5e8f9a80 (patch)
tree4f82f011f6782cca18650ea28080d8636b15fb81 /tests/lookup
parent3346b78a8a872286a245d1e77ef4718fc5e6be1a (diff)
downloaddjango-0719edcd5fed56157ffb3323a8f634aa5e8f9a80.tar.gz
Fixed #30771 -- Fixed exact lookup against queries with selected columns.
Use pre-existing select fields (and thereby GROUP BY fields) from subquery if they were specified, instead of always defaulting to pk. Thanks Aur Saraf for the report and Simon Charette for guidance.
Diffstat (limited to 'tests/lookup')
-rw-r--r--tests/lookup/tests.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py
index a603824c0d..1958b995b2 100644
--- a/tests/lookup/tests.py
+++ b/tests/lookup/tests.py
@@ -5,6 +5,7 @@ from operator import attrgetter
from django.core.exceptions import FieldError
from django.db import connection
+from django.db.models import Max
from django.db.models.expressions import Exists, OuterRef
from django.db.models.functions import Substr
from django.test import TestCase, skipUnlessDBFeature
@@ -956,3 +957,15 @@ class LookupTests(TestCase):
),
)
self.assertEqual(qs.get(has_author_alias_match=True), tag)
+
+ def test_exact_query_rhs_with_selected_columns(self):
+ newest_author = Author.objects.create(name='Author 2')
+ authors_max_ids = Author.objects.filter(
+ name='Author 2',
+ ).values(
+ 'name',
+ ).annotate(
+ max_id=Max('id'),
+ ).values('max_id')
+ authors = Author.objects.filter(id=authors_max_ids[:1])
+ self.assertEqual(authors.get(), newest_author)