summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sanders <shang.xiao.sanders@gmail.com>2023-09-20 23:58:23 +1000
committerNatalia <124304+nessita@users.noreply.github.com>2023-09-21 13:17:32 -0300
commitfb5dd118e955e34c84effc295aaabcec12e6295b (patch)
tree406c2f58006f884dd2429cd152f01677b21fcd92
parent6db8e46e470bb27481c3dc489f8fe687eae7cca6 (diff)
[5.0.x] Refs #34808 -- Doc'd that aggregation functions on empty groups can return None.
Backport of 78b5c9075348aa12da2e024f6ece29d1d652dfdd from main
-rw-r--r--docs/ref/models/querysets.txt15
1 files changed, 8 insertions, 7 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index cd6c13fc05..5c4760a868 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -3845,14 +3845,15 @@ documentation to learn how to create your aggregates.
currently emulates these features using a text field. Attempts to use
aggregation on date/time fields in SQLite will raise ``NotSupportedError``.
-.. admonition:: Empty queryset
+.. admonition:: Empty querysets or groups
- Aggregation functions return ``None`` when used with an empty
- ``QuerySet``. For example, the ``Sum`` aggregation function returns ``None``
- instead of ``0`` if the ``QuerySet`` contains no entries. To return another
- value instead, pass a value to the ``default`` argument. An exception is
- ``Count``, which does return ``0`` if the ``QuerySet`` is empty. ``Count``
- does not support the ``default`` argument.
+ Aggregation functions return ``None`` when used with an empty ``QuerySet``
+ or group. For example, the ``Sum`` aggregation function returns ``None``
+ instead of ``0`` if the ``QuerySet`` contains no entries or for any empty
+ group in a non-empty ``QuerySet``. To return another value instead, define
+ the ``default`` argument. ``Count`` is an exception to this behavior; it
+ returns ``0`` if the ``QuerySet`` is empty since ``Count`` does not support
+ the ``default`` argument.
All aggregates have the following parameters in common: