Skip to content

Not required DecimalField in nested Serializer gives error on empty input in browsable API #3233

@jgadelange

Description

@jgadelange

I have a nested serializer with a DecimalField(required=False). Implemented something like stated below:

class SubSerializer(serializers.Serializer):
    # This one gives errors when leaving the form input in browsable api empty:
    sub_field = serializers.DecimalField(required=False)


class MainSerializer(serializers.Serializer):
    # This shows behaviour I expext:
    main_field = serializers.DecimalField(required=False)
    sub = SubSerializer()

When I now use the browsable API I get a form as expected (a main field, sub field and a header for the Sub serializer). When I leave both inputs empty, I will only get an error for sub_field saying: A valid number is required. not for main_field.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions