mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Refs #35060 -- Adjusted deprecation warning stacklevel in Model.save()/asave().
This commit is contained in:
parent
a69f895d7d
commit
52ed2b645e
@ -788,7 +788,7 @@ class Model(AltersData, metaclass=ModelBase):
|
|||||||
warnings.warn(
|
warnings.warn(
|
||||||
f"Passing positional arguments to {method_name}() is deprecated",
|
f"Passing positional arguments to {method_name}() is deprecated",
|
||||||
RemovedInDjango60Warning,
|
RemovedInDjango60Warning,
|
||||||
stacklevel=2,
|
stacklevel=3,
|
||||||
)
|
)
|
||||||
total_len_args = len(args) + 1 # include self
|
total_len_args = len(args) + 1 # include self
|
||||||
max_len_args = len(defaults) + 1
|
max_len_args = len(defaults) + 1
|
||||||
|
@ -19,3 +19,7 @@ Bugfixes
|
|||||||
children). A new :class:`~django.contrib.auth.forms.AdminUserCreationForm`
|
children). A new :class:`~django.contrib.auth.forms.AdminUserCreationForm`
|
||||||
including this field was added, isolating the feature to the admin where it
|
including this field was added, isolating the feature to the admin where it
|
||||||
was intended (:ticket:`35678`).
|
was intended (:ticket:`35678`).
|
||||||
|
|
||||||
|
* Adjusted the deprecation warning ``stacklevel`` in :meth:`.Model.save` and
|
||||||
|
:meth:`.Model.asave` to correctly point to the offending call site
|
||||||
|
(:ticket:`35060`).
|
||||||
|
@ -206,9 +206,10 @@ class ModelInstanceCreationTests(TestCase):
|
|||||||
def test_save_deprecation(self):
|
def test_save_deprecation(self):
|
||||||
a = Article(headline="original", pub_date=datetime(2014, 5, 16))
|
a = Article(headline="original", pub_date=datetime(2014, 5, 16))
|
||||||
msg = "Passing positional arguments to save() is deprecated"
|
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)
|
a.save(False, False, None, None)
|
||||||
self.assertEqual(Article.objects.count(), 1)
|
self.assertEqual(Article.objects.count(), 1)
|
||||||
|
self.assertEqual(ctx.filename, __file__)
|
||||||
|
|
||||||
def test_save_deprecation_positional_arguments_used(self):
|
def test_save_deprecation_positional_arguments_used(self):
|
||||||
a = Article()
|
a = Article()
|
||||||
@ -259,9 +260,10 @@ class ModelInstanceCreationTests(TestCase):
|
|||||||
async def test_asave_deprecation(self):
|
async def test_asave_deprecation(self):
|
||||||
a = Article(headline="original", pub_date=datetime(2014, 5, 16))
|
a = Article(headline="original", pub_date=datetime(2014, 5, 16))
|
||||||
msg = "Passing positional arguments to asave() is deprecated"
|
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)
|
await a.asave(False, False, None, None)
|
||||||
self.assertEqual(await Article.objects.acount(), 1)
|
self.assertEqual(await Article.objects.acount(), 1)
|
||||||
|
self.assertEqual(ctx.filename, __file__)
|
||||||
|
|
||||||
async def test_asave_deprecation_positional_arguments_used(self):
|
async def test_asave_deprecation_positional_arguments_used(self):
|
||||||
a = Article()
|
a = Article()
|
||||||
|
@ -262,10 +262,11 @@ class UpdateOnlyFieldsTests(TestCase):
|
|||||||
|
|
||||||
msg = "Passing positional arguments to save() is deprecated"
|
msg = "Passing positional arguments to save() is deprecated"
|
||||||
with (
|
with (
|
||||||
self.assertWarnsMessage(RemovedInDjango60Warning, msg),
|
self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx,
|
||||||
self.assertNumQueries(0),
|
self.assertNumQueries(0),
|
||||||
):
|
):
|
||||||
s.save(False, False, None, [])
|
s.save(False, False, None, [])
|
||||||
|
self.assertEqual(ctx.filename, __file__)
|
||||||
|
|
||||||
async def test_empty_update_fields_positional_asave(self):
|
async def test_empty_update_fields_positional_asave(self):
|
||||||
s = await Person.objects.acreate(name="Sara", gender="F")
|
s = await Person.objects.acreate(name="Sara", gender="F")
|
||||||
@ -273,8 +274,9 @@ class UpdateOnlyFieldsTests(TestCase):
|
|||||||
s.name = "Other"
|
s.name = "Other"
|
||||||
|
|
||||||
msg = "Passing positional arguments to asave() is deprecated"
|
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, [])
|
await s.asave(False, False, None, [])
|
||||||
|
self.assertEqual(ctx.filename, __file__)
|
||||||
|
|
||||||
# No save occurred for an empty update_fields.
|
# No save occurred for an empty update_fields.
|
||||||
await s.arefresh_from_db()
|
await s.arefresh_from_db()
|
||||||
|
Loading…
Reference in New Issue
Block a user