From 5e81a4e7900f105971f332efd1702b5dd7f628ac Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Fri, 9 Aug 2024 12:39:18 -0400 Subject: [PATCH] Refs #12581 -- Adjusted warning stacklevel in queries ring buffer. --- django/db/backends/base/base.py | 3 ++- tests/backends/tests.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/django/db/backends/base/base.py b/django/db/backends/base/base.py index 7a1dfd30d1..e6e0325d07 100644 --- a/django/db/backends/base/base.py +++ b/django/db/backends/base/base.py @@ -175,7 +175,8 @@ class BaseDatabaseWrapper: if len(self.queries_log) == self.queries_log.maxlen: warnings.warn( "Limit for query logging exceeded, only the last {} queries " - "will be returned.".format(self.queries_log.maxlen) + "will be returned.".format(self.queries_log.maxlen), + stacklevel=2, ) return list(self.queries_log) diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 4bab62aebb..2adfa51360 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -558,8 +558,9 @@ class BackendTestCase(TransactionTestCase): "Limit for query logging exceeded, only the last 3 queries will be " "returned." ) - with self.assertWarnsMessage(UserWarning, msg): + with self.assertWarnsMessage(UserWarning, msg) as ctx: self.assertEqual(3, len(new_connection.queries)) + self.assertEqual(ctx.filename, __file__) finally: BaseDatabaseWrapper.queries_limit = old_queries_limit