chore: Catch obsolete properties usage

This commit is contained in:
Serhii Tereshchenko 2025-02-11 14:13:01 +02:00
parent 398ba98e1b
commit 969080f02e

View File

@ -5,13 +5,14 @@ In addition, Django's built in 403 and 404 exceptions are handled.
(`django.http.Http404` and `django.core.exceptions.PermissionDenied`) (`django.http.Http404` and `django.core.exceptions.PermissionDenied`)
""" """
import math import math
import warnings
from django.http import JsonResponse from django.http import JsonResponse
from django.utils.encoding import force_str from django.utils.encoding import force_str
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext from django.utils.translation import ngettext
from rest_framework import status from rest_framework import RemovedInDRF317Warning, status
from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList
@ -233,12 +234,18 @@ class Throttled(APIException):
detail = force_str(self.default_detail) detail = force_str(self.default_detail)
if wait is not None: if wait is not None:
wait = math.ceil(wait) wait = math.ceil(wait)
detail = " ".join((detail, force_str(self.extra_detail(wait)))) detail = " ".join((detail, self.extra_detail(wait)))
self.wait = wait self.wait = wait
super().__init__(detail, code) super().__init__(detail, code)
@staticmethod def extra_detail(self, wait):
def extra_detail(wait): if hasattr(self, 'extra_detail_singular') or hasattr(self, 'extra_detail_plural'):
warnings.warn("You're using incorrect way of specifying extra_detail, please override `extra_detail` instead. This will be removed in DRF 3.17", RemovedInDRF317Warning)
return ngettext(
getattr(self, 'extra_detail_singular', 'Expected available in {wait} second.'),
getattr(self, 'extra_detail_plural', 'Expected available in {wait} seconds.'),
wait,
).format(wait=wait)
return ngettext( return ngettext(
'Expected available in {wait} second.', 'Expected available in {wait} second.',
'Expected available in {wait} seconds.', 'Expected available in {wait} seconds.',