From 55a0073b3beb9de8f7c1f7c44a7d0bc10126c841 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Wed, 19 Mar 2025 01:11:34 -0400 Subject: Refs #27222 -- Refreshed GeneratedFields values on save() initiated update. This required implementing UPDATE RETURNING machinery that heavily borrows from the INSERT one. --- docs/ref/models/fields.txt | 12 ++++++------ docs/releases/6.0.txt | 9 +++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index dd0862926a..f105096c8c 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -1315,12 +1315,6 @@ materialized view. PostgreSQL only supports persisted columns. Oracle only supports virtual columns. -.. admonition:: Refresh the data - - Since the database computes the value, the object must be reloaded to - access the new value after :meth:`~Model.save`, for example, by using - :meth:`~Model.refresh_from_db`. - .. admonition:: Database limitations There are many database-specific restrictions on generated fields that @@ -1338,6 +1332,12 @@ materialized view. .. _PostgreSQL: https://www.postgresql.org/docs/current/ddl-generated-columns.html .. _SQLite: https://www.sqlite.org/gencol.html#limitations +.. versionchanged:: 6.0 + + ``GeneratedField``\s are now automatically refreshed from the database on + backends that support it (SQLite, PostgreSQL, and Oracle) and marked as + deferred otherwise. + ``GenericIPAddressField`` ------------------------- diff --git a/docs/releases/6.0.txt b/docs/releases/6.0.txt index e11a16162a..0d5565176f 100644 --- a/docs/releases/6.0.txt +++ b/docs/releases/6.0.txt @@ -331,6 +331,12 @@ Models value from the non-null input values. This is supported on SQLite, MySQL, Oracle, and PostgreSQL 16+. +* :class:`~django.db.models.GeneratedField`\s are now refreshed from the + database after :meth:`~django.db.models.Model.save` on backends that support + the ``RETURNING`` clause (SQLite, PostgreSQL, and Oracle). On backends that + don't support it (MySQL and MariaDB), the fields are marked as deferred to + trigger a refresh on subsequent accesses. + Pagination ~~~~~~~~~~ @@ -420,6 +426,9 @@ backends. ``returning_params`` to be provided just like ``fetch_returned_insert_columns()`` did. +* If the database supports ``UPDATE … RETURNING`` statements, backends can set + ``DatabaseFeatures.can_return_rows_from_update=True``. + Dropped support for MariaDB 10.5 -------------------------------- -- cgit v1.3