Opened 45 hours ago
Last modified 45 hours ago
#36142 new Cleanup/optimization
django.shortcuts.get_object_or_404 does not support translation for error messages (i18n)
Reported by: | Abror Izzatullaev | Owned by: | |
---|---|---|---|
Component: | Internationalization | Version: | 5.2 |
Severity: | Normal | Keywords: | i18 Internationalization |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
class WheatProvidingViewSet(viewsets.ModelViewSet): queryset = WheatProviding.objects.all() serializer_class = WheatProvidingSerializer def destroy(self, request, *args, **kwargs): instance = self.get_object()
The code above demonstrates a Django REST Framework (DRF) ModelViewSet. When a non-existent ID is provided, the destroy method raises a 404 Not Found error. However, the error message is not translated.
The root cause of this issue is that ModelViewSet relies on Django’s get_object_or_404 function, which does not support internationalization (i18n) for its error messages.
Could you consider adding support for translations in the get_object_or_404 function? This enhancement would allow DRF to natively support localized error messages, improving its usability in multilingual applications.
Change History (1)
comment:1 by , 45 hours ago
Description: | modified (diff) |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | 5.1 → 5.2 |
I think that localizing that message makes sense as it is potentially user-facing, as the use case in the ticket description shows.