Relation fields no to_fields attribute attribute break serializer · Issue #3634 · encode/django-rest-framework (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
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.