#31136: Multiple annotations with Exists() should not group by aliases. -------------------------------------+------------------------------------- Reporter: Sigurd Ljødal | Owner: felixxm Type: Bug | Status: new Component: Database layer | Version: 3.0 (models, ORM) | Severity: Release blocker | Resolution: Keywords: | Triage Stage: Accepted Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by felixxm):
* status: closed => new * resolution: fixed => Comment: I found a regression in this fix when I was trying to reproduce #31150, see {{{ diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index f523b3ca35..0209a9221b 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1165,6 +1165,27 @@ class AggregateTestCase(TestCase): 'Sams', ]) + def test_aggregation_subquery_annotation_distinct(self): + books_qs = Book.objects.annotate( + first_author_the_same_age=Subquery( + Author.objects.filter( + age=OuterRef('contact__friends__age'), + ).order_by('age').values('id')[:1], + ) + ).filter( + publisher=self.p1, + first_author_the_same_age__isnull=False, + ).annotate( + min_age=Min('contact__friends__age'), + ).values('name', 'min_age').distinct() + self.assertEqual(list(books_qs),[ + { + 'name': 'The Definitive Guide to Django: Web Development Done Right', + 'min_age': 29, + }, + {'name': 'Practical Django Projects', 'min_age': 34}, + ]) + @skipUnlessDBFeature('supports_subqueries_in_group_by') def test_group_by_subquery_annotation(self): """ }}} -- Ticket URL: <https://code.djangoproject.com/ticket/31136#comment:6> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.36e0e1768635b4efa905b0ac99472351%40djangoproject.com.