Skip to content

Commit aead842

Browse files
committed
Address review: internationalize the executemany label
Use ngettext for the repeat count and move the changelog entry into Pending, which a release moved out from under it.
1 parent a342130 commit aead842

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

debug_toolbar/panels/sql/tracking.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import django.test.testcases
88
from django.apps import apps
99
from django.core.exceptions import ImproperlyConfigured
10+
from django.utils.translation import gettext as _, ngettext
1011

1112
from debug_toolbar import settings as dt_settings
1213
from debug_toolbar.sanitize import force_str
@@ -227,8 +228,13 @@ def _record(self, method, sql, params, *, many=False):
227228
try:
228229
times = len(params)
229230
except TypeError:
230-
times = "?"
231-
display_sql = f"{times} times: {sql}"
231+
display_sql = _("? times: %(sql)s") % {"sql": sql}
232+
else:
233+
display_sql = ngettext(
234+
"%(count)d time: %(sql)s",
235+
"%(count)d times: %(sql)s",
236+
times,
237+
) % {"count": times, "sql": sql}
232238
else:
233239
display_sql = self._last_executed_query(sql, params)
234240

docs/changes.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Pending
2222
* Updated the example screenshot.
2323
* Updated the screenshot capture logic to find the toolbar elements in the
2424
shadow DOM.
25+
* Fixed ``cursor.executemany()`` raising from the SQL panel instead of being
26+
recorded. The statement is now shown as ``N times: <sql>``, matching
27+
Django's own debug cursor.
2528

2629
7.1.1 (2026-08-14)
2730
------------------
@@ -48,9 +51,6 @@ Pending
4851
* Stopped the history panel buttons from submitting their form when clicked
4952
before the panel script has loaded, which navigated away from the page.
5053
* Added support for Django 6.1.
51-
* Fixed ``cursor.executemany()`` raising from the SQL panel instead of being
52-
recorded. The statement is now shown as ``N times: <sql>``, matching
53-
Django's own debug cursor.
5454

5555
7.0.0 (2026-06-17)
5656
------------------

tests/panels/test_sql.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ def test_executemany(self):
129129
self.assertTrue(query["many"])
130130
self.assertEqual(Binary.objects.count(), 2)
131131

132+
def test_executemany_singular(self):
133+
"""A single param set uses the singular form."""
134+
self.assertEqual(len(self.panel._queries), 0)
135+
136+
with connection.cursor() as cursor:
137+
cursor.executemany(
138+
"INSERT INTO tests_binary (field) VALUES (%s)", [(b"one",)]
139+
)
140+
141+
self.assertEqual(len(self.panel._queries), 1)
142+
self.assertEqual(
143+
self.panel._queries[0]["sql"],
144+
"1 time: INSERT INTO tests_binary (field) VALUES (%s)",
145+
)
146+
self.assertEqual(Binary.objects.count(), 1)
147+
132148
def test_executemany_with_empty_param_list(self):
133149
"""An empty param list runs no statement but must still not raise."""
134150
self.assertEqual(len(self.panel._queries), 0)

0 commit comments

Comments
 (0)