* owner: nobody => Simon Charette
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34750#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Simon Charette):
I don't think I'll be able to make the cut for 4.2.4 but I have an idea of
our to address this issue so I self assigned.
--
Ticket URL: <https://code.djangoproject.com/ticket/34750#comment:3>
Comment (by Mariusz Felisiak):
Replying to [comment:3 Simon Charette]:
> I don't think I'll be able to make the cut for 4.2.4 but I have an idea
of our to address this issue so I self assigned.
We can postpone 4.2.4 for a few days.
--
Ticket URL: <https://code.djangoproject.com/ticket/34750#comment:4>
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>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34750#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"c9b9a52edc66be117c6e5b5214fa788a4d5db7a8" c9b9a52]:
{{{
#!CommitTicketReference repository=""
revision="c9b9a52edc66be117c6e5b5214fa788a4d5db7a8"
Fixed #34750 -- Fixed QuerySet.count() when grouping by unused multi-
valued annotations.
Thanks Toan Vuong for the report.
Thanks Simon Charette for the review.
Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34750#comment:7>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"8808d9da6b11b8aa32d750265217721450b0fb1f" 8808d9d]:
{{{
#!CommitTicketReference repository=""
revision="8808d9da6b11b8aa32d750265217721450b0fb1f"
[4.2.x] Fixed #34750 -- Fixed QuerySet.count() when grouping by unused
multi-valued annotations.
Thanks Toan Vuong for the report.
Thanks Simon Charette for the review.
Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7.
Backport of c9b9a52edc66be117c6e5b5214fa788a4d5db7a8 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34750#comment:8>