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

Refs #12581 -- Adjusted warning stacklevel in queries ring buffer.

This commit is contained in:
Simon Charette 2024-08-09 12:39:18 -04:00 committed by nessita
parent 2b9f0b79bc
commit 5e81a4e790
2 changed files with 4 additions and 2 deletions

View File

@ -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)

View File

@ -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