#34750: Fixed QuerySet.count() on querysets grouped by unused multi-valued
annotations.
-------------------------------------+-------------------------------------
Reporter: Toan Vuong | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):
I've prepared a regression test:
{{{#!diff
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
index 9f2a7c8841..8bdeaca97d 100644
--- a/tests/aggregation/tests.py
+++ b/tests/aggregation/tests.py
@@ -2165,6 +2165,25 @@ class AggregateAnnotationPruningTests(TestCase):
self.assertEqual(sql.count("select"), 2, "Subquery wrapping
required")
self.assertNotIn("authors_count", sql)
+ def test_unused_aliased_aggregate_and_annotation_reverse_fk(self):
+ Book.objects.create(
+ name="b3",
+ publisher=self.p2,
+ pages=1000,
+ rating=4.2,
+ price=50,
+ contact=self.a2,
+ pubdate=datetime.date.today(),
+ )
+ qs = Publisher.objects.annotate(
+ total_pages=Sum("book__pages"),
+ good_book=Case(
+ When(book__rating__gt=4.0, then=Value(True)),
+ default=Value(False),
+ ),
+ )
+ self.assertEqual(qs.count(), 3)
+
def test_non_aggregate_annotation_pruned(self):
with CaptureQueriesContext(connection) as ctx:
Book.objects.annotate(
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34750#comment:5>
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 on the web visit
https://groups.google.com/d/msgid/django-updates/01070189abb970d6-e3b442a9-25ed-4cf4-96cf-94c440100ea4-000000%40eu-central-1.amazonses.com.