Validate serializations

Hi,

I am using Django to create an API, but I am encountering an issue with validation serializers. Here is my serializer class:

class InputSerializer(serializers.Serializer):
    keyword = serializers.CharField(required=True, allow_blank=False, allow_null=False)
    vi_name = serializers.CharField(required=False, allow_blank=False, allow_null=False)

The problem is the validation succeed when I send a request with {‘keyword’: ‘a’, ‘vi_name’:‘’} (I mean ‘vi_name’ is blank).

How to make the serializer validation fail when I send ‘vi_name’ blank or null?
Thank you!

Well, accordingly to the schema you provided, it should already be failing the validation.
Can you double check the input data that you’re receiving in your view?

Also note that both allow_null and allow_blank already defaults to False

1 Like