Skip to content

allow_null=True is not being passed to ListSerializer constructor in many_init #2673

Closed
@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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions