summaryrefslogtreecommitdiff
path: root/tests/update_only_fields
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2024-06-25 17:12:10 +0100
committerGitHub <noreply@github.com>2024-06-25 13:12:10 -0300
commit28522c3c8d5eb581347aececc3ac61c134528114 (patch)
tree90293cc1fe2d278aee8783a2ab4f287e4cbe3eeb /tests/update_only_fields
parentbcc327aa326093a39f01a9bc98198807444900f3 (diff)
Fixed #35554, Refs #35060 -- Corrected deprecated *args parsing in Model.save()/asave().
The transitional logic added to deprecate the usage of *args for Model.save()/asave() introduced two issues that this branch fixes: * Passing extra positional arguments no longer raised TypeError. * Passing a positional but empty update_fields would save all fields. Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
Diffstat (limited to 'tests/update_only_fields')
-rw-r--r--tests/update_only_fields/tests.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/update_only_fields/tests.py b/tests/update_only_fields/tests.py
index 6c23ae27d8..816112bc33 100644
--- a/tests/update_only_fields/tests.py
+++ b/tests/update_only_fields/tests.py
@@ -1,5 +1,6 @@
from django.db.models.signals import post_save, pre_save
from django.test import TestCase
+from django.utils.deprecation import RemovedInDjango60Warning
from .models import Account, Employee, Person, Profile, ProxyEmployee
@@ -256,6 +257,29 @@ class UpdateOnlyFieldsTests(TestCase):
pre_save.disconnect(pre_save_receiver)
post_save.disconnect(post_save_receiver)
+ def test_empty_update_fields_positional_save(self):
+ s = Person.objects.create(name="Sara", gender="F")
+
+ msg = "Passing positional arguments to save() is deprecated"
+ with (
+ self.assertWarnsMessage(RemovedInDjango60Warning, msg),
+ self.assertNumQueries(0),
+ ):
+ s.save(False, False, None, [])
+
+ async def test_empty_update_fields_positional_asave(self):
+ s = await Person.objects.acreate(name="Sara", gender="F")
+ # Workaround for a lack of async assertNumQueries.
+ s.name = "Other"
+
+ msg = "Passing positional arguments to asave() is deprecated"
+ with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
+ await s.asave(False, False, None, [])
+
+ # No save occurred for an empty update_fields.
+ await s.arefresh_from_db()
+ self.assertEqual(s.name, "Sara")
+
def test_num_queries_inheritance(self):
s = Employee.objects.create(name="Sara", gender="F")
s.employee_num = 1