0
0
mirror of https://github.com/django/django.git synced 2024-11-21 19:09:18 +01:00

Refs #16055 -- Adjusted deprecation warning stacklevel in get_joining_columns()/get_reverse_joining_columns().

This commit is contained in:
Simon Charette 2024-08-09 13:49:59 -04:00 committed by nessita
parent 5e81a4e790
commit 8ee17037ae
3 changed files with 9 additions and 3 deletions

View File

@ -781,6 +781,7 @@ class ForeignObject(RelatedField):
"ForeignObject.get_joining_columns() is deprecated. Use "
"get_joining_fields() instead.",
RemovedInDjango60Warning,
stacklevel=2,
)
source = self.reverse_related_fields if reverse_join else self.related_fields
return tuple(
@ -792,6 +793,7 @@ class ForeignObject(RelatedField):
"ForeignObject.get_reverse_joining_columns() is deprecated. Use "
"get_reverse_joining_fields() instead.",
RemovedInDjango60Warning,
stacklevel=2,
)
return self.get_joining_columns(reverse_join=True)

View File

@ -197,6 +197,7 @@ class ForeignObjectRel(FieldCacheMixin):
"ForeignObjectRel.get_joining_columns() is deprecated. Use "
"get_joining_fields() instead.",
RemovedInDjango60Warning,
stacklevel=2,
)
return self.field.get_reverse_joining_columns()

View File

@ -703,24 +703,27 @@ class GetJoiningDeprecationTests(TestCase):
"ForeignObject.get_joining_columns() is deprecated. Use "
"get_joining_fields() instead."
)
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
Membership.person.field.get_joining_columns()
self.assertEqual(ctx.filename, __file__)
def test_foreign_object_get_reverse_joining_columns_warning(self):
msg = (
"ForeignObject.get_reverse_joining_columns() is deprecated. Use "
"get_reverse_joining_fields() instead."
)
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
Membership.person.field.get_reverse_joining_columns()
self.assertEqual(ctx.filename, __file__)
def test_foreign_object_rel_get_joining_columns_warning(self):
msg = (
"ForeignObjectRel.get_joining_columns() is deprecated. Use "
"get_joining_fields() instead."
)
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
Membership.person.field.remote_field.get_joining_columns()
self.assertEqual(ctx.filename, __file__)
def test_join_get_joining_columns_warning(self):
class CustomForeignKey(models.ForeignKey):