#36025: __range lookup in conditional aggregate with subquery annotation does 
not
use annotated related fields
-------------------------------------+-------------------------------------
     Reporter:  Aashay Amballi       |                    Owner:  (none)
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  ORM                  |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Gregory Mariani):

 Can't reproduce with the minimal example. I get:
 {{{ {'out_of_bound_count': 0, 'project_id_subquery_sum': 3} }}}
 with that script:
 {{{
 project1 = Project.objects.create(
     start_date='2024-01-01',
     end_date='2024-06-30')

 project2 = Project.objects.create(
     start_date='2024-07-01',
     end_date='2024-12-31')

 due_date1 = timezone.make_aware(timezone.datetime(2024, 4, 15, 10, 0, 0))
 due_date2 = timezone.make_aware(timezone.datetime(2024, 10, 1, 12, 0, 0))

 work_order1 = WorkOrder.objects.create(
     project=project1,
     due_date=due_date1,
 )

 work_order2 = WorkOrder.objects.create(
     project=project2,
     due_date=due_date1,
 )

 result = WorkOrder.objects.annotate(
     project_id_subquery=Subquery(Project.objects.filter(
         id=OuterRef("project_id")).values("id")),
 ).aggregate(
     out_of_bound_count=Count("id", filter=Q(due_date__date__range=(
         F('project__start_date'), F('project__end_date')))),
     project_id_subquery_sum=Sum("project_id_subquery"),
 )
 print(result)
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36025#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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070193defb1895-5d1daaa3-b898-4384-bc14-4e03c653e59d-000000%40eu-central-1.amazonses.com.

Reply via email to