summaryrefslogtreecommitdiff
path: root/tests/update_only_fields
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2025-03-19 01:39:19 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2025-09-14 00:27:50 +0200
commit94680437a45a71c70ca8bd2e68b72aa1e2eff337 (patch)
tree0246e0b5a8dde81f0a327e1c7c7e3accd9257870 /tests/update_only_fields
parent55a0073b3beb9de8f7c1f7c44a7d0bc10126c841 (diff)
Fixed #27222 -- Refreshed model field values assigned expressions on save().
Removed the can_return_columns_from_insert skip gates on existing field_defaults tests to confirm the expected number of queries are performed and that returning field overrides are respected.
Diffstat (limited to 'tests/update_only_fields')
-rw-r--r--tests/update_only_fields/tests.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/tests/update_only_fields/tests.py b/tests/update_only_fields/tests.py
index 9595c767eb..1c7ef88832 100644
--- a/tests/update_only_fields/tests.py
+++ b/tests/update_only_fields/tests.py
@@ -1,5 +1,6 @@
from django.core.exceptions import ObjectNotUpdated
-from django.db import DatabaseError, transaction
+from django.db import DatabaseError, connection, transaction
+from django.db.models import F
from django.db.models.signals import post_save, pre_save
from django.test import TestCase
@@ -308,3 +309,16 @@ class UpdateOnlyFieldsTests(TestCase):
transaction.atomic(),
):
obj.save(update_fields=["name"])
+
+ def test_update_fields_expression(self):
+ obj = Person.objects.create(name="Valerie", gender="F", pid=42)
+ updated_pid = F("pid") + 1
+ obj.pid = updated_pid
+ obj.save(update_fields={"gender"})
+ self.assertIs(obj.pid, updated_pid)
+ obj.save(update_fields={"pid"})
+ expected_num_queries = (
+ 0 if connection.features.can_return_rows_from_update else 1
+ )
+ with self.assertNumQueries(expected_num_queries):
+ self.assertEqual(obj.pid, 43)