Changes between Initial Version and Version 1 of Ticket #34024, comment 4


Ignore:
Timestamp:
Sep 21, 2022, 6:12:43 AM (2 years ago)
Author:
David Sanders

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #34024, comment 4

    initial v1  
    1 Here's a simple boiled down failing test case:
     1FYI: none of the original tests from the PR introducing WhereNode.is_summary were testing with Q
     2
     3Here's a simplified failing test case to go alongside those added with the PR:
    24
    35{{{
    4 diff --git a/tests/queries/tests.py b/tests/queries/tests.py
    5 index 1bd72dd8b8..c6d9b05761 100644
    6 --- a/tests/queries/tests.py
    7 +++ b/tests/queries/tests.py
    8 @@ -1312,6 +1312,10 @@ class Queries1Tests(TestCase):
     6diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py
     7index e15e7e41d9..cc92029135 100644
     8--- a/tests/aggregation_regress/tests.py
     9+++ b/tests/aggregation_regress/tests.py
     10@@ -554,6 +554,10 @@ class AggregationTests(TestCase):
     11             325,
    912         )
    10          self.assertSequenceEqual(Note.objects.exclude(negate=True), [self.n3])
    1113
    12 +    def test_count_on_annotation(self):
    13 +        # Ticket: #34024
    14 +        Tag.objects.annotate(has_pk=~Q(pk=None)).count()
     14+    def test_q_annotation_aggregate(self):
     15+        # Ensure aggregation works with annotations using Q objects
     16+        Book.objects.annotate(has_pk=~Q(pk=None)).count()
    1517+
    16 
    17  class Queries2Tests(TestCase):
    18      @classmethod
     18     def test_decimal_aggregate_annotation_filter(self):
     19         """
     20         Filtering on an aggregate annotation with Decimal values should work.
    1921}}}
    20 
    21 results
    22 
    23 {{{
    24 E
    25 ======================================================================
    26 ERROR: test_count_on_annotation (queries.tests.Queries1Tests)
    27 ----------------------------------------------------------------------
    28 Traceback (most recent call last):
    29   File "/Users/davids/projects/django/tests/queries/tests.py", line 1317, in test_count_on_annotation
    30     Tag.objects.annotate(has_pk=~Q(pk=None)).count()
    31   File "/Users/davids/projects/django/django/db/models/query.py", line 621, in count
    32     return self.query.get_count(using=self.db)
    33   File "/Users/davids/projects/django/django/db/models/sql/query.py", line 554, in get_count
    34     return obj.get_aggregation(using, ["__count"])["__count"]
    35   File "/Users/davids/projects/django/django/db/models/sql/query.py", line 503, in get_aggregation
    36     if expression.is_summary:
    37 AttributeError: 'WhereNode' object has no attribute 'is_summary'
    38 
    39 ----------------------------------------------------------------------
    40 Ran 1 test in 0.014s
    41 
    42 FAILED (errors=1)
    43 Destroying test database for alias 'default'...
    44 }}}
Back to Top