allow_null=True is not being passed to ListSerializer constructor in many_init · Issue #2673 · encode/django-rest-framework (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@delinhabit

Description

@delinhabit

Hello,

We have a use case where we accept either a list of objects or null. The problem is that BaseSerializer.many_init is not passing the allow_null argument to the ListSerializer constructor. because of that I have validation errors even if the field was specified with allow_null=True.

He's an example:

class PaymentInfoSerializer(serializers.Serializer): url = serializer.CharField() amount = serializers.DecimalField()

def validate(self, attrs):
    """
    This is never being called
    """

class Request(serializers.Serializer): payment_info = PaymentInfoSerializer( many=True, required=False, allow_null=True)

Basically LIST_SERIALIZER_KWARGS (defined here) does not include allow_null and therefore the arguments is not passed to the ListSerializer constructor (details here).

Is there a reason why allow_null should not be sent to the list serializer?

Thanks!