From 7a0416c50bfd663b5690c563d7448f2a10d414d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Padilla?= Date: Fri, 7 Aug 2015 13:12:37 -0400 Subject: [PATCH] Raise error if passed a serializer instance --- rest_framework/response.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rest_framework/response.py b/rest_framework/response.py index 47d9476558..3f038e3b5f 100644 --- a/rest_framework/response.py +++ b/rest_framework/response.py @@ -10,6 +10,8 @@ from django.utils import six from django.utils.six.moves.http_client import responses +from rest_framework.serializers import Serializer + class Response(SimpleTemplateResponse): """ @@ -28,6 +30,15 @@ def __init__(self, data=None, status=None, For example being set automatically by the `APIView`. """ super(Response, self).__init__(None, status=status) + + if isinstance(data, Serializer): + msg = ( + 'You passed a Serializer instance as data, but ' + 'probably meant to pass serialized `.data` or ' + '`.error`. representation.' + ) + raise AssertionError(msg) + self.data = data self.template_name = template_name self.exception = exception pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy