diff options
| author | Simon Charette <charette.s@gmail.com> | 2025-03-19 01:39:19 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2025-09-14 00:27:50 +0200 |
| commit | 94680437a45a71c70ca8bd2e68b72aa1e2eff337 (patch) | |
| tree | 0246e0b5a8dde81f0a327e1c7c7e3accd9257870 /tests/expressions | |
| parent | 55a0073b3beb9de8f7c1f7c44a7d0bc10126c841 (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/expressions')
| -rw-r--r-- | tests/expressions/tests.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 27d88be621..6f18321aa7 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -420,8 +420,11 @@ class BasicExpressionsTests(TestCase): # F expressions can be used to update attributes on single objects self.gmbh.num_employees = F("num_employees") + 4 self.gmbh.save() - self.gmbh.refresh_from_db() - self.assertEqual(self.gmbh.num_employees, 36) + expected_num_queries = ( + 0 if connection.features.can_return_rows_from_update else 1 + ) + with self.assertNumQueries(expected_num_queries): + self.assertEqual(self.gmbh.num_employees, 36) def test_new_object_save(self): # We should be able to use Funcs when inserting new data @@ -1644,8 +1647,11 @@ class ExpressionsNumericTests(TestCase): n = Number.objects.create(integer=1, decimal_value=Decimal("0.5")) n.decimal_value = F("decimal_value") - Decimal("0.4") n.save() - n.refresh_from_db() - self.assertEqual(n.decimal_value, Decimal("0.1")) + expected_num_queries = ( + 0 if connection.features.can_return_rows_from_update else 1 + ) + with self.assertNumQueries(expected_num_queries): + self.assertEqual(n.decimal_value, Decimal("0.1")) class ExpressionOperatorTests(TestCase): |
