Not handling Validation error for nested serializers
bedilbek opened this issue · comments
Hi, thanks for this repo.
I got one issue when working with a nested serializer.
Let's say I have a UserSerializer
with nested foreign key extra_info
class UserSerializer(serializers.Serializer):
class UserExtraInfoSerializer(serializers.Serializer):
mobile_phone_number = serializers.CharField(max_length=15, required=True)
first_name = serializers.CharField(max_length=100)
extra_info = UserExtraInfoSerializer()
Then, let's assume client wants to send a request with the below POST data to the view handled by UserSerializer
:
{"first_name": "Someone", "extra_info": {}}
The client should receive ValidationError, because when extra_info
is present mobile_phone_number
is required. But because it is not handled in drf-exceptions-hog
. I guess I found the place where the fix is necessary:
drf-exceptions-hog/exceptions_hog/handler.py
Lines 97 to 98 in 7547549
Because we are handling nested serializer, we need to have one more condition to check if there is dict inside (the best even iterate over all dictionaries to find the root). I will find a workaround for my project, maybe even make PR, hopefully