diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-01-05 10:09:46 -0500 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-07 11:42:06 +0100 |
| commit | 470e5545e56e8510f9b9d39a96d7094fedd9c45a (patch) | |
| tree | 371d33bcc1bcbbf205137aa6627b17fa4f751e6f /docs | |
| parent | 6eec703667505d87d1354323548943c8d546c5a2 (diff) | |
Refs #36042 -- Raised ValueError when providing composite expressions to aggregates.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/expressions.txt | 8 | ||||
| -rw-r--r-- | docs/releases/5.2.txt | 4 | ||||
| -rw-r--r-- | docs/topics/composite-primary-key.txt | 10 |
3 files changed, 19 insertions, 3 deletions
diff --git a/docs/ref/models/expressions.txt b/docs/ref/models/expressions.txt index f273b00a9e..6faec969c3 100644 --- a/docs/ref/models/expressions.txt +++ b/docs/ref/models/expressions.txt @@ -1105,6 +1105,14 @@ calling the appropriate methods on the wrapped expression. ``UNNEST``, etc.) to skip optimization and be properly evaluated when annotations spawn rows themselves. Defaults to ``False``. + .. attribute:: allows_composite_expressions + + .. versionadded:: 5.2 + + Tells Django that this expression allows composite expressions, for + example, to support :ref:`composite primary keys + <cpk-and-database-functions>`. Defaults to ``False``. + .. method:: resolve_expression(query=None, allow_joins=True, reuse=None, summarize=False, for_save=False) Provides the chance to do any preprocessing or validation of diff --git a/docs/releases/5.2.txt b/docs/releases/5.2.txt index 35c602c4e2..f1d68d234f 100644 --- a/docs/releases/5.2.txt +++ b/docs/releases/5.2.txt @@ -330,6 +330,10 @@ Models accepts a list of field names or expressions and returns a JSON array containing those values. +* The new :attr:`.Expression.allows_composite_expressions` attribute specifies + that the expression allows composite expressions, for example, to support + :ref:`composite primary keys <cpk-and-database-functions>`. + Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/topics/composite-primary-key.txt b/docs/topics/composite-primary-key.txt index 9e5234ca9f..f252f318c1 100644 --- a/docs/topics/composite-primary-key.txt +++ b/docs/topics/composite-primary-key.txt @@ -131,6 +131,8 @@ database. ``ForeignObject`` is an internal API. This means it is not covered by our :ref:`deprecation policy <internal-release-deprecation-policy>`. +.. _cpk-and-database-functions: + Composite primary keys and database functions ============================================= @@ -141,13 +143,15 @@ Many database functions only accept a single expression. MAX("order_id") -- OK MAX("product_id", "order_id") -- ERROR -As a consequence, they cannot be used with composite primary key references as -they are composed of multiple column expressions. +In these cases, providing a composite primary key reference raises a +``ValueError``, since it is composed of multiple column expressions. An +exception is made for ``Count``. .. code-block:: python Max("order_id") # OK - Max("pk") # ERROR + Max("pk") # ValueError + Count("pk") # OK Composite primary keys in forms =============================== |
