#31580: Expect to get SELECT DISTINCT ON after UNION of 2 annotated QuerySet -------------------------------------+------------------------------------- Reporter: Sielc | Owner: nobody Type: Bug | Status: new Component: Database | Version: 3.0 layer (models, ORM) | Keywords: orm, distinct, Severity: Normal | annotate, union Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- After using - .annotate() on 2 different querysets - and then .union() - .distinct() will not affect the queryset
{{{ def setUp(self) -> None: user = self.get_or_create_admin_user() Sample.h.create(user, name="Sam1") Sample.h.create(user, name="Sam2 acid") Sample.h.create(user, name="Sam3") Sample.h.create(user, name="Sam4 acid") Sample.h.create(user, name="Dub") Sample.h.create(user, name="Dub") Sample.h.create(user, name="Dub") self.user = user def test_union_annotated_diff_distinct(self): qs = Sample.objects.filter(user=self.user) qs1 = qs.filter(name='Dub').annotate(rank=Value(0, IntegerField())) qs2 = qs.filter(name='Sam1').annotate(rank=Value(1, IntegerField())) qs = qs1.union(qs2) qs = qs.order_by('name').distinct('name') # THIS DISTINCT DONESN'T WORK self.assertEqual(qs.count(), 2) }}} expected to get wrapped union {{{ SELECT DISTINCT ON (siebox_sample.name) * FROM (SELECT ... UNION SELECT ...) AS siebox_sample }}} -- Ticket URL: <https://code.djangoproject.com/ticket/31580> 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/048.a39e433875cc17a4bed98b6ea33575a7%40djangoproject.com.