Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#14754 closed (fixed)

TypeError: '[some aggregate function]' object does not support indexing

Reported by: master Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: relabel_aliases, aggregate
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Relabelling aliases on the query value, when this value is an Aggregate object, is expected.

A simplified example (don't look for a sense, it's just for the demo):

from django.contrib.auth.models import User
emails = User.objects.values('email').annotate(
    cnt=Count('id'),
    some_int=Count('username')
).filter(some_int=F('cnt')).values_list('email', flat=True)
print User.objects.filter(email__in=emails).query

produces:

  File "D:\Python26\lib\site-packages\django-svn\django\db\models\sql\query.py", line 709, in change_aliases
    self.having.relabel_aliases(change_map)
  File "D:\Python26\lib\site-packages\django-svn\django\db\models\sql\where.py", line 251, in relabel_aliases
    child[3].relabel_aliases(change_map)
  File "D:\Python26\lib\site-packages\django-svn\django\db\models\sql\expressions.py", line 22, in relabel_aliases
    self.cols[node] = (change_map.get(col[0], col[0]), col[1])
TypeError: 'Count' object does not support indexing

A patch is provided, for django\db\models\sql\expressions.py

Attachments (1)

aggregates_relabel_aliases.diff (723 bytes ) - added by master 14 years ago.

Download all attachments as: .zip

Change History (3)

by master, 14 years ago

comment:1 by Alex Gaynor, 14 years ago

Resolution: fixed
Status: newclosed

(In [14681]) Fixed #14754 -- corrected using an aggregate in an F expressions when that queryset is later used in a subquery. Thanks to master for the patch.

comment:2 by Alex Gaynor, 14 years ago

(In [14682]) [1.2.X] Fixed #14754 -- corrected using an aggregate in an F expressions when that queryset is later used in a subquery. Thanks to master for the patch. Backport of [14681].

Note: See TracTickets for help on using tickets.
Back to Top