Skip to content

ModelSerializer dies on IntegerField with a max_length argument #2317

Closed
@hakanw

Description

@hakanw

If an IntegerField, or PositiveIntegerField or any other number field has a max_length argument, then any serialization fails.

Here's the stacktrace:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/hakan/.virtualenvs/opinion/lib/python2.7/site-packages/rest_framework/serializers.py", line 434, in __repr__
    return unicode_to_repr(representation.serializer_repr(self, indent=1))
  File "/Users/hakan/.virtualenvs/opinion/lib/python2.7/site-packages/rest_framework/utils/representation.py", line 75, in serializer_repr
    fields = serializer.fields
  File "/Users/hakan/.virtualenvs/opinion/lib/python2.7/site-packages/rest_framework/serializers.py", line 312, in fields
    for key, value in self.get_fields().items():
  File "/Users/hakan/.virtualenvs/opinion/lib/python2.7/site-packages/rest_framework/serializers.py", line 1044, in get_fields
    ret[field_name] = field_cls(**kwargs)
  File "/Users/hakan/.virtualenvs/opinion/lib/python2.7/site-packages/rest_framework/fields.py", line 647, in __init__
    super(IntegerField, self).__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'max_length'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions