1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[5.1.x] Refs #35060 -- Adjusted deprecation warning stacklevel in Model.save()/asave().

Backport of 52ed2b645e from main.
This commit is contained in:
Simon Charette
2024-08-09 13:41:18 -04:00
committed by Natalia
parent e435b44be6
commit c87007ab60
4 changed files with 13 additions and 5 deletions

View File

@@ -206,9 +206,10 @@ class ModelInstanceCreationTests(TestCase):
def test_save_deprecation(self):
a = Article(headline="original", pub_date=datetime(2014, 5, 16))
msg = "Passing positional arguments to save() is deprecated"
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
a.save(False, False, None, None)
self.assertEqual(Article.objects.count(), 1)
self.assertEqual(ctx.filename, __file__)
def test_save_deprecation_positional_arguments_used(self):
a = Article()
@@ -259,9 +260,10 @@ class ModelInstanceCreationTests(TestCase):
async def test_asave_deprecation(self):
a = Article(headline="original", pub_date=datetime(2014, 5, 16))
msg = "Passing positional arguments to asave() is deprecated"
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
await a.asave(False, False, None, None)
self.assertEqual(await Article.objects.acount(), 1)
self.assertEqual(ctx.filename, __file__)
async def test_asave_deprecation_positional_arguments_used(self):
a = Article()

View File

@@ -262,10 +262,11 @@ class UpdateOnlyFieldsTests(TestCase):
msg = "Passing positional arguments to save() is deprecated"
with (
self.assertWarnsMessage(RemovedInDjango60Warning, msg),
self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx,
self.assertNumQueries(0),
):
s.save(False, False, None, [])
self.assertEqual(ctx.filename, __file__)
async def test_empty_update_fields_positional_asave(self):
s = await Person.objects.acreate(name="Sara", gender="F")
@@ -273,8 +274,9 @@ class UpdateOnlyFieldsTests(TestCase):
s.name = "Other"
msg = "Passing positional arguments to asave() is deprecated"
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
await s.asave(False, False, None, [])
self.assertEqual(ctx.filename, __file__)
# No save occurred for an empty update_fields.
await s.arefresh_from_db()