Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#22710 closed Cleanup/optimization (fixed)

Document aggregation behaviour for empty querysets

Reported by: Aleksey Kladov Owned by: Guillaume Pannatier
Component: Documentation Version: 1.6
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

Description

It is not stated in the documentation that aggregation operations return None for empty queryset. Relevant docs are here (https://docs.djangoproject.com/en/dev/topics/db/aggregation/) and here (https://docs.djangoproject.com/en/dev/ref/models/querysets/#aggregation-functions).

It is rather obvious if you think about it for a second, but may be a surprise if you use aggregation for the first time. So I suggest adding a note about None for empty queryset.

PS. I've used aggregation API for the first time today. It was a migration. I've tested it on local machine and on dev server, it was OK. And then, blast!, 'foo column can not be null' during migration on the production server =)

Change History (11)

comment:1 by Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:2 by Guillaume Pannatier, 10 years ago

Owner: changed from nobody to Guillaume Pannatier
Status: newassigned

comment:3 by Guillaume Pannatier, 10 years ago

comment:4 by Guillaume Pannatier, 10 years ago

Has patch: set

comment:5 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 7c6e96ec1f99289740132135895be83776cc9ca5:

Fixed #22710 -- Documented aggregation behavior for empty QuerySets.

Thanks matklad for the report.

comment:6 by Tim Graham <timograham@…>, 10 years ago

In b266392b638c188daf3621e7f919cc12d65a4e2a:

[1.7.x] Fixed #22710 -- Documented aggregation behavior for empty QuerySets.

Thanks matklad for the report.

Backport of 7c6e96ec1f from master

comment:7 by jarshwah, 10 years ago

I don't think the documentation here is technically correct. Count() does return 0 instead of None, because it is specifically coerced. It is the only aggregate that doesn't return None.

comment:8 by Tim Graham, 10 years ago

Has patch: unset
Resolution: fixed
Status: closednew

comment:9 by Guillaume Pannatier, 10 years ago

Has patch: set
Status: newassigned

Sorry for this error.
The new PR for review :
https://github.com/django/django/pull/2761

comment:10 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 08bd249fa2ac938d35b93b2686c0c439ca160127:

[1.6.x] Fixed #22710 -- Amended aggregation note for empty QuerySets

Thanks smeaton for report and Joël Rochat for spell check

Backport of 7f27cca5c5 from master

comment:11 by Tim Graham <timograham@…>, 10 years ago

In 52b7e772e4da846efb2d75b22ec05c7105091b76:

[1.7.x] Fixed #22710 -- Amended aggregation note for empty QuerySets

Thanks smeaton for report and Joël Rochat for spell check

Backport of 7f27cca5c5 from master

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