Skip to content

Commit 76cc34a

Browse files
committed
fix: Fix invalid ngettext usage in Throttled exception.
Format should be called after ngettext. If you have overridden `extra_detail_singular` or `extra_detail_plural`, you should now replace them with a single `def extra_detail` override. Refs: https://docs.djangoproject.com/en/5.1/topics/i18n/translation/#pluralization
1 parent d3dd45b commit 76cc34a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

rest_framework/exceptions.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,24 @@ def __init__(self, media_type, detail=None, code=None):
226226
class Throttled(APIException):
227227
status_code = status.HTTP_429_TOO_MANY_REQUESTS
228228
default_detail = _('Request was throttled.')
229-
extra_detail_singular = _('Expected available in {wait} second.')
230-
extra_detail_plural = _('Expected available in {wait} seconds.')
231229
default_code = 'throttled'
232230

233231
def __init__(self, wait=None, detail=None, code=None):
234232
if detail is None:
235233
detail = force_str(self.default_detail)
236234
if wait is not None:
237235
wait = math.ceil(wait)
238-
detail = ' '.join((
239-
detail,
240-
force_str(ngettext(self.extra_detail_singular.format(wait=wait),
241-
self.extra_detail_plural.format(wait=wait),
242-
wait))))
236+
detail = " ".join((detail, force_str(self.extra_detail(wait))))
243237
self.wait = wait
244238
super().__init__(detail, code)
245239

240+
def extra_detail(self, wait):
241+
return ngettext(
242+
'Expected available in {wait} second.',
243+
'Expected available in {wait} seconds.',
244+
wait,
245+
).format(wait=wait)
246+
246247

247248
def server_error(request, *args, **kwargs):
248249
"""

0 commit comments

Comments
 (0)