#34978: Annotating through an aggregate with RawSQL() raises 1056 "Can't group 
on"
on MySQL/MariaDB.
-------------------------------------+-------------------------------------
     Reporter:  Matthew Somerville   |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    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 David Sanders):

 Failing test in case that helps:

 {{{
 --- a/tests/aggregation/tests.py
 +++ b/tests/aggregation/tests.py
 @@ -2135,6 +2135,39 @@ class AggregateTestCase(TestCase):
          )
          self.assertEqual(list(author_qs), [337])

 +    def test_annotate_raw_expression(self):
 +        qs = (
 +            Book.objects.values("publisher")
 +            .annotate(min_price=Min("price"))
 +            .annotate(max_price=RawSQL("MAX(price)", params=[]))
 +            .values("publisher__name", "min_price", "max_price")
 +        )
 +        self.assertEqual(
 +            list(qs),
 +            [
 +                {
 +                    "max_price": Decimal("30.00"),
 +                    "min_price": Decimal("29.69"),
 +                    "publisher__name": "Apress",
 +                },
 +                {
 +                    "max_price": Decimal("23.09"),
 +                    "min_price": Decimal("23.09"),
 +                    "publisher__name": "Sams",
 +                },
 +                {
 +                    "max_price": Decimal("82.80"),
 +                    "min_price": Decimal("29.69"),
 +                    "publisher__name": "Prentice Hall",
 +                },
 +                {
 +                    "max_price": Decimal("75.00"),
 +                    "min_price": Decimal("75.00"),
 +                    "publisher__name": "Morgan Kaufmann",
 +                },
 +            ],
 +        )
 +

  class AggregateAnnotationPruningTests(TestCase):
      @classmethod
 }}}

 This one's interesting because we can't dig into RawSQL to determine
 whether it's valid in a GROUP BY or not.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34978#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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018bebfa65d9-c5674800-1c9a-45f3-b4c6-e7be178f2aba-000000%40eu-central-1.amazonses.com.

Reply via email to