#29608: Query with several filtered annotation on different related objects
-------------------------------------+-------------------------------------
Reporter: Etienne Chove | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: 2.0.7 model | Triage Stage:
annotation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Etienne Chove:
Old description:
> 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
> }}}
New description:
Hello,
This test code fails (inserted in tests/annotations/tests.py) on django
2.0.7.
The first and the second annotation works when then are executed alone...
but when executed together, the result differ from alone-executions.
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#comment:2>
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/065.589fccc9d38cfa37097c43642a630b88%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.