Skip to content

Relation fields no to_fields attribute attribute break serializer #3634

Closed
@martinhill

Description

@martinhill

Hello,

I have a ModelSerializer for the django-taggit package's Tag model. With DRF release 3.3.1 it began failing with AttributeError: 'TaggableManager' object has no attribute 'to_fields'.

I believe this line from PR 3526 assumes all relation fields have a to_fields attribute, but taggit's TaggableManager is an example of one that doesn't.

Replacing it with

    return field.to_fields[0] if hasattr(field, 'to_fields') else None

seems to solve the problem.

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