estebistec / drf-compound-fields

Django-REST-framework serializer fields for compound types.
BSD 3-Clause "New" or "Revised" License
92 stars 12 forks source link

ListField: redundant validation call that runs at wrong time #30

Closed anentropic closed 5 years ago

anentropic commented 5 years ago

This causes spurious validation errors when using 'partial' serializers (PATCH requests) in DRF

I first noticed it because I would see errors like picture_ids: %(value)s is not a list in my tests

I started looking into why the %(value)s was not substituted into the error string, suspecting a bug in our error response code

but it turns out due to exception being raised in the wrong phase by drf_compound_fields

when validation is performed at the normal time by DRF the value gets substituted properly https://github.com/encode/django-rest-framework/blob/2.4.4/rest_framework/fields.py#L326

I confirmed also that the validate_is_list method still gets called as intended after removing this line

I'm not sure why this validation call was added on this line originally, but the tests pass without it and removing it seems to prevent spurious errors

anentropic commented 5 years ago

just realised this fix only applies to very old version 0.2.2