#29608: Query with several filtered annotation on different related objects
-------------------------------------+-------------------------------------
               Reporter:  Etienne    |          Owner:  nobody
  Chove                              |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.0
  layer (models, ORM)                |       Keywords:  2.0.7 model
               Severity:  Normal     |  annotation
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Hello,

 This test code fails (inserted in tests/annotations/tests.py) on django
 2.0.7.

 Etienne

 {{{
     def test_filtered_annotation_several_related_objects(self):
         amazon=Store.objects.get(name='Amazon.com')

         # create employees
         Employee(first_name="E1", last_name="E1", store=amazon, age=30,
 salary=0).save()
         Employee(first_name="E2", last_name="E2", store=amazon, age=70,
 salary=0).save()

         # annotations
         a1 = Count("books", filter=Q(books__pages__gt=400))
         a2 = Count("employee", filter=Q(employee__age__gt=60))

         # first annotation
         stores1 = Store.objects.annotate(big_books=a1)
         s1 = stores1.get(pk=amazon.pk)
         self.assertEqual(s1.big_books, 4)

         # second annotation
         stores2 = Store.objects.annotate(old_employee=a2)
         s2 = stores2.get(pk=amazon.pk)
         self.assertEqual(s2.old_employee, 1)

         # together
         stores3 = Store.objects.annotate(big_books=a1, old_employee=a2)
         s3 = stores3.get(pk=amazon.pk)
         self.assertEqual(s3.old_employee, s2.old_employee)
         self.assertEqual(s3.big_books, s1.big_books)
 }}}

 The result is :
 {{{
 ======================================================================
 FAIL: test_filtered_annotation_several_related_objects
 (aggregation.tests.NonAggregateAnnotationTestCase)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "C:\Users\[...]\tests.py", line 627, in
 test_filtered_annotation_several_related_objects
     self.assertEqual(s3.old_employee, s2.old_employee)
 AssertionError: 6 != 1
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29608>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.a8512bdc0eb48d414156e006a4b2cf4d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to