summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorVyacheslav Dmitriev <rtefforg@gmail.com>2023-07-20 20:02:17 +0300
committerGitHub <noreply@github.com>2023-07-20 14:02:17 -0300
commitb126f694160c4641e64e57dba6b022f06fbfa745 (patch)
treefd003f844395c033124967c6039a9db5c9d276c7 /docs
parentd7d80040c1e3a282435155f9974e1eafa8da66e5 (diff)
Refs #30052 -- Clarified that defer() and only() do not work with aggregated fields.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/querysets.txt10
1 files changed, 8 insertions, 2 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index fd6bb39ff8..93193acfad 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -1709,6 +1709,11 @@ never defer the loading of the primary key. If you are using
loading of the field that connects from the primary model to the related
one, doing so will result in an error.
+Similarly, calling ``defer()`` (or its counterpart :meth:`only()`) including an
+argument from an aggregation (e.g. using the result of :meth:`annotate()`)
+doesn't make sense: doing so will raise an exception. The aggregated values
+will always be fetched into the resulting queryset.
+
.. note::
The ``defer()`` method (and its cousin, :meth:`only()`, below) are only for
@@ -1803,8 +1808,9 @@ All of the cautions in the note for the :meth:`defer` documentation apply to
``only()`` as well. Use it cautiously and only after exhausting your other
options.
-Using :meth:`only` and omitting a field requested using :meth:`select_related`
-is an error as well.
+Using ``only()`` and omitting a field requested using :meth:`select_related` is
+an error as well. On the other hand, invoking ``only()`` without any arguments,
+will return every field (including annotations) fetched by the queryset.
As with ``defer()``, you cannot access the non-loaded fields from asynchronous
code and expect them to load. Instead, you will get a