diff options
Diffstat (limited to 'tests/update_only_fields/tests.py')
| -rw-r--r-- | tests/update_only_fields/tests.py | 16 |
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) |
