-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Description
Problem
aget_object_or_404 in adrf/generics.py catches rest_framework.exceptions.ValidationError, but Django's field validation raises django.core.exceptions.ValidationError for invalid field types (e.g., invalid UUID strings). Invalid values aren't converted to Http404 as intended.
Current Code
https://github.com/em1208/adrf/blob/87f599fefbc88a7a750b22a89369f9c3823efc83/adrf/generics.py
from rest_framework.exceptions import ValidationError
...
except (TypeError, ValueError, ValidationError):
raise Http404Expected Behavior
Invalid field types (like invalid UUIDs) should raise Http404 instead of letting django.core.exceptions.ValidationError propagate.
Reference
DRF's get_object_or_404 uses Django's ValidationError: https://github.com/encode/django-rest-framework/blob/365d409adb43ebad7d8a42cab2407ec841d8038e/rest_framework/generics.py#L13
Fix
Change the import to:
from django.core.exceptions import ValidationErrorMetadata
Metadata
Assignees
Labels
No labels