djangorestframework-stubs icon indicating copy to clipboard operation
djangorestframework-stubs copied to clipboard

Fields named as Serializer properties throws assignment error

Open lundberg opened this issue 5 years ago • 2 comments

If a serializer has a field named the same as DRF's Serializer class properties; data, errors and fields, an assignment error will be thrown.

lundberg avatar Jul 03 '20 13:07 lundberg

I'm having the same issue but with a field named label Code:


class RiskFieldSerializer(serializers.Serializer):
    id = serializers.CharField()
    label = serializers.CharField()
    status = serializers.CharField()

Error message:

Incompatible types in assignment (expression has type "CharField", base class "Field" defined the type as "Optional[str]")

hensg avatar Jul 11 '22 23:07 hensg

just ran into this with a field named label, glad this issue is open or i never would have solved it

Brodan avatar Mar 25 '24 05:03 Brodan