#36352: Weird behavior of .values after a distinct in 5.1.8
-------------------------------------+-------------------------------------
     Reporter:  Joseph Yu            |                    Owner:  (none)
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  5.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:  .values, distinct    |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

 * resolution:   => needsinfo
 * status:  new => closed

Comment:

 {{{#!python
 from django.db import models
 from django.db.models import (
     F,
     OuterRef,
     Subquery,
 )
 from django.test import TestCase


 class Tenant(models.Model):
     schema_name = models.CharField(max_length=150)
     created_at = models.DateTimeField(auto_now_add=True)


 class Test36352(TestCase):
     def test_ticket_36352(self):
         t1 = Tenant.objects.create(schema_name="Test 1")
         t2 = Tenant.objects.create(schema_name="Test 2")
         t3 = Tenant.objects.create(schema_name="Test 3")
         a = Tenant.objects.filter(id__in=[t1.id,
 t1.id]).values('id').annotate(
             schema=F('schema_name'), created=F('created_at')
         )
         b = Tenant.objects.filter(id=t1.id).values('id').annotate(
             schema=F('schema_name'), created=F('created_at')
         )
         c = (a | b).distinct()
         d = c.filter(id=OuterRef('id')).values('schema')
         e = Tenant.objects.values('schema_name').annotate(
             created_at=Subquery(d.values('created'))
         )
 }}}

 So yes this fails, but it seems to fail in Django 4.2 as well. It might
 help sharing the model as well. It would also be useful to do a git bisect
 to identify when this started failing
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36352#comment:3>
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019671e51343-48faf355-e554-4731-be05-d349e484e145-000000%40eu-central-1.amazonses.com.

Reply via email to