From 18d8f818e0032c8d6288a51c4cb66a5d835001a9 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Sat, 19 Oct 2013 20:05:38 -0700 Subject: [PATCH] check for isinstance Page, prevents alt pagination when using DEFAULT_PAGINATION_SERIALIZER_CLASS and a custom paginator_class BaseSerializer's checking for isinstance Page doesn't work. the custom paginator_class has it's own Page that doesn't inherit from django's base Page and thus its __iter__ method causes many=True, and iterating over the page and trying to serialize the objects through DEFAULT_PAGINATION_SERIALIZER_CLASS. --- rest_framework/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 4210d058b..cd564e6d4 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -520,7 +520,7 @@ class BaseSerializer(WritableField): if self.many is not None: many = self.many else: - many = hasattr(obj, '__iter__') and not isinstance(obj, (Page, dict)) + many = hasattr(obj, '__iter__') and not (isinstance(obj, dict) or hasattr(obj, 'next_page_number')) if many: warnings.warn('Implict list/queryset serialization is deprecated. ' 'Use the `many=True` flag when instantiating the serializer.',