Opened 5 years ago

Closed 5 years ago

#16688 closed Bug (duplicate)

unionagg doesn't respect limits

Reported by: arc <django-bugs@…> Owned by: nobody
Component: GIS Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When specifying a limit with slice syntax and then running unionagg, this limit is not taken into account. In the below example, unionagg is run on the entire set of records rather than only 10 records as expected:

qs = Model.objects.all()[:10]
ua = qs.unionagg()

Change History (2)

comment:1 Changed 5 years ago by aaugustin

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

Slicing a QuerySet basically tacks "LIMIT foo" at the end of the generated SQL. As a consequence, the slicing applies after the aggregation.

The same problem is handled properly in the case of filter: MyModel.objects.filter(...)[:10].filter(...) raises AssertionError: Cannot filter a query once a slice has been taken.

I think aggregating a query after a slice has been taken should also raise an AssertionError.

comment:2 Changed 5 years ago by anonymous

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

Duplicate of #15101 (Extent aggregate instead).

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