#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 , 11 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 11 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 11 years ago
comment:4 by , 11 years ago
| Has patch: | set |
|---|
comment:5 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
comment:7 by , 11 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 , 11 years ago
| Has patch: | unset |
|---|---|
| Resolution: | fixed |
| Status: | closed → new |
comment:9 by , 11 years ago
| Has patch: | set |
|---|---|
| Status: | new → assigned |
Sorry for this error.
The new PR for review :
https://github.com/django/django/pull/2761
comment:10 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
The PR for review
https://github.com/django/django/pull/2735