Fix TypeError bug in ListSerializer.to_representation

The `iterable` can potentially be a subclass of `BaseManager` (and not
necessarily `Manager`), which leads to a `TypeError` as the `isinstance`
check fails (so a queryset is not obtained before iteration is
attempted).
This commit is contained in:
Rob Golding 2018-01-28 21:02:03 +00:00
parent c1cc3ada7b
commit 130b83623e
No known key found for this signature in database
GPG Key ID: 8CC8F8E9495DE340

View File

@ -20,7 +20,7 @@ from collections import Mapping, OrderedDict
from django.core.exceptions import ValidationError as DjangoValidationError
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.db.models import DurationField as ModelDurationField
from django.db.models import manager, DurationField as ModelDurationField
from django.db.models.fields import Field as DjangoModelField
from django.db.models.fields import FieldDoesNotExist
from django.utils import six, timezone
@ -654,7 +654,7 @@ class ListSerializer(BaseSerializer):
"""
# Dealing with nested relationships, data can be a Manager,
# so, first get a queryset from the Manager if needed
iterable = data.all() if isinstance(data, models.Manager) else data
iterable = data.all() if isinstance(data, manager.BaseManager) else data
return [
self.child.to_representation(item) for item in iterable