#31880: Incorrect handling of aggregate's keyword name
-------------------------------------+-------------------------------------
               Reporter:  Thodoris   |          Owner:  nobody
  Sotiropoulos                       |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:  Database   |        Version:  3.1
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I have the following model (simplified for opening the issue).

 {{{#!python
 class T(models.Model):
   id = models.AutoField(primary=True)
   foo = models.IntegerField()
 }}}

 and I perform the following query on MySQL (simplified for opening the
 issue)

 {{{#!python
 T.objects.annotate(anon=F('foo')).aggregate(foo=Max(F('anon')),
 sum=Sum(F('foo')))
 }}}

 this produces the following SQL query

 {{{#!sql
 SELECT MAX(`anon`), SUM(`foo`) FROM (SELECT `table`.`foo` AS `anon` FROM
 `foo`) subquery
 }}}

 that causes the following exception

 {{{
 django.db.utils.OperationalError: (1054, "Unknown column 'foo' in 'field
 list'")
 }}}

 I would expect django to generate

 {{{#!sql
 SELECT MAX(`anon`), SUM(`anon`) FROM (SELECT `table`.`foo` AS `anon` FROM
 `table`) subquery
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31880>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.2c5aa1a34b4f6fc76f2b8cae6995fd06%40djangoproject.com.

Reply via email to