Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 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: master
Severity: Keywords: relabel_aliases, aggregate
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation:
Needs tests: Patch needs improvement:
Easy pickings: UI/UX:

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 3 years ago.

Download all attachments as: .zip

Change History (3)

Changed 3 years ago by master

comment:1 Changed 3 years ago by Alex

  • Resolution set to fixed
  • Status changed from new to closed

(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 Changed 3 years ago by Alex

(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].

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.