#25171: Can't update queryset after Count annotation
-------------------------------------+-------------------------------------
     Reporter:  fraserharris         |      Owner:  nobody
         Type:  Bug                  |     Status:  new
    Component:  Database layer       |    Version:  1.6
  (models, ORM)                      |   Keywords:  queryset, update,
     Severity:  Normal               |  filter
 Triage Stage:  Unreviewed           |  Has patch:  0
Easy pickings:  0                    |      UI/UX:  0
-------------------------------------+-------------------------------------
 Query:
 {{{
 >>> Category.objects.annotate(Count('tiles')).update(name='foo')
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/opt/secondfunnel/venv/local/lib/python2.7/site-
 packages/django/db/models/query.py", line 490, in update
     rows = query.get_compiler(self.db).execute_sql(None)
   File "/opt/secondfunnel/venv/local/lib/python2.7/site-
 packages/django/db/models/sql/compiler.py", line 976, in execute_sql
     cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
   File "/opt/secondfunnel/venv/local/lib/python2.7/site-
 packages/django/db/models/sql/compiler.py", line 782, in execute_sql
     cursor.execute(sql, params)
   File "/opt/secondfunnel/venv/local/lib/python2.7/site-
 packages/django/db/backends/util.py", line 69, in execute
     return super(CursorDebugWrapper, self).execute(sql, params)
   File "/opt/secondfunnel/venv/local/lib/python2.7/site-
 packages/django/db/backends/util.py", line 53, in execute
     return self.cursor.execute(sql, params)
   File "/opt/secondfunnel/venv/local/lib/python2.7/site-
 packages/django/db/utils.py", line 99, in __exit__
     six.reraise(dj_exc_type, dj_exc_value, traceback)
   File "/opt/secondfunnel/venv/local/lib/python2.7/site-
 packages/django/db/backends/util.py", line 53, in execute
     return self.cursor.execute(sql, params)
 ProgrammingError: subquery has too many columns
 LINE 1: ..." SET "name" = 'foo' WHERE "assets_category"."id" IN (SELECT...
                                                              ^
 }}}

 Models:
 {{{
 class Category(BaseModel):
     tiles = models.ManyToManyField(Tile, related_name='categories')
     name = models.CharField(max_length=255)

 class Tile(Model):
     pass
 }}}

 SQL Query from django.db.connections.queries:
 {{{
 UPDATE "assets_category" SET "name" = \'foo\' WHERE "assets_category"."id"
 IN (SELECT U0."id", COUNT(U2."tile_id") AS "tiles__count" FROM
 "assets_category" U0 LEFT OUTER JOIN "assets_category_tiles" U2 ON (
 U0."id" = U2."category_id" ) GROUP BY U0."id", U0."name")
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25171>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/055.e6b1fcdf805f4b0f5c28c64a83d76e09%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to