Opened 6 years ago

Last modified 23 hours ago

#11671 new Bug

Aggregations add extra values to ValuesQuerySets :: another usecase

Reported by: richard@… Owned by:
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: QuerySet.extra
Cc: klemens@…, jorgecarleitao@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Looking at #10132 I see a similar complaint, however, in this case... the extra.select variable is not included in the values/group_by but is annotated.

>>> qs = TblCdr.objects.extra(select={'billable':'IF(billsec=0,0,1)'},).values('network').annotate(Sum('billable')
... )
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 580, in annotate
    is_summary=False)
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py", line 1471, in add_aggregate
    field_list, opts, self.get_initial_alias(), False)
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py", line 1737, in setup_joins
    "Choices are: %s" % (name, ", ".join(names)))
FieldError: Cannot resolve keyword 'billable' into field. Choices are: billsec, cause, cli, codec, country_code, dcontext, disposition, dst, duration, end, id, ip, lastapp, network, note, start, supplier

Change History (11)

comment:1 Changed 6 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by thejaswi_puthraya

  • Component changed from Uncategorized to ORM aggregation
  • Owner nobody deleted

comment:3 Changed 5 years ago by fetzig

  • Cc klemens@… added

comment:4 Changed 5 years ago by fetzig

don't know, but i think i have the same problem #13363. the exception is very similar.

is it complex to create a patch for this, or is it just something nobody did yet?

comment:5 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:6 Changed 4 years ago by anonymous

  • Version changed from 1.1 to SVN

Patching this would be very helpfull as, this feature would be usefull in clustering (geodjango)

e.objects.extra(select={'cluster':'substring(mortons_code for 10)'}).annotate(objects_in_cluster=Count('cluster')).order_by('objects_in_cluster')

same error:

FieldError: Cannot resolve keyword 'cluster' into field. Choices are:


.....

comment:7 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:8 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:9 Changed 2 years ago by akaariai

  • Component changed from ORM aggregation to Database layer (models, ORM)

comment:10 Changed 13 months ago by jorgecarleitao

  • Cc jorgecarleitao@… added

comment:11 Changed 23 hours ago by timgraham

  • Keywords QuerySet.extra added
Note: See TracTickets for help on using tickets.
Back to Top