Opened 6 years ago
Last modified 6 years ago
#29608 closed Bug
Query with several filtered annotation on different related objects — at Version 2
Reported by: | Etienne Chove | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.0 |
Severity: | Normal | Keywords: | 2.0.7 model annotation |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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
Change History (2)
comment:1 by , 6 years ago
Severity: | Normal → Release blocker |
---|
comment:2 by , 6 years ago
Description: | modified (diff) |
---|
Note:
See TracTickets
for help on using tickets.