Opened 5 years ago

Closed 5 years ago

#28277 closed Cleanup/optimization (fixed)

Validate that annotate() and aggregate() args and kwarg values are expressions

Reported by: Tim Graham Owned by: Mariusz Felisiak
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The current error messages are unhelpful. For example:

>>> Book.objects.aggregate(alias=Max('price'), output_field=FloatField())
  File "/home/tim/code/django/django/db/models/sql/", line 974, in add_annotation
    annotation = annotation.resolve_expression(self, allow_joins=True, reuse=None,
AttributeError: 'FloatField' object has no attribute 'resolve_expression'


>>> Book.objects.annotate(FloatField()))
  File "/home/tim/code/django/django/db/models/", line 890, in annotate
    if arg.default_alias in kwargs:
AttributeError: 'FloatField' object has no attribute 'default_alias'

Change History (3)

comment:1 Changed 5 years ago by Mariusz Felisiak

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:2 Changed 5 years ago by Mariusz Felisiak

Has patch: set

comment:3 Changed 5 years ago by GitHub <noreply@…>

Resolution: fixed
Status: assignedclosed

In 6e228d0b:

Fixed #28277 -- Added validation of QuerySet.annotate() and aggregate() args.

Thanks Tim Graham and Nick Pope for reviews.

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