From a69f895d7de198d7082cd7275390fa2d2a3d5619 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Fri, 9 Aug 2024 12:57:58 -0400 Subject: [PATCH] Refs #34547 -- Adjusted deprecation warning stacklevel in DatabaseOperations.field_cast_sql(). --- django/db/backends/base/operations.py | 1 + tests/backends/base/test_operations.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index 889e4d87b4..dba9fcbba8 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -228,6 +228,7 @@ class BaseDatabaseOperations: "DatabaseOperations.lookup_cast() instead." ), RemovedInDjango60Warning, + stacklevel=2, ) return "%s" diff --git a/tests/backends/base/test_operations.py b/tests/backends/base/test_operations.py index 8df02ee76b..18433352ad 100644 --- a/tests/backends/base/test_operations.py +++ b/tests/backends/base/test_operations.py @@ -239,8 +239,9 @@ class DeprecationTests(TestCase): "DatabaseOperations.field_cast_sql() is deprecated use " "DatabaseOperations.lookup_cast() instead." ) - with self.assertRaisesMessage(RemovedInDjango60Warning, msg): + with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx: base_ops.field_cast_sql("integer", "IntegerField") + self.assertEqual(ctx.filename, __file__) def test_field_cast_sql_usage_warning(self): compiler = Author.objects.all().query.get_compiler(connection.alias)