Skip to content

Raising ValidationError from Serializer.to_internal_value() with error message(s) as list causes ValueError #3864

@ryochiji

Description

@ryochiji
>>> from rest_framework.serializers import Serializer
>>> from rest_framework.exceptions import ValidationError
>>> class FooSerializer(Serializer):
...   def to_internal_value(self, data):
...     raise ValidationError(['foo error'])
... 
>>> foo = FooSerializer(data={})
>>> foo.is_valid(raise_exception=True)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/altschool/vishnu-backend/lib/python2.7/site-packages/rest_framework/serializers.py", line 221, in is_valid
    raise ValidationError(self.errors)
  File "/usr/local/altschool/vishnu-backend/lib/python2.7/site-packages/rest_framework/serializers.py", line 509, in errors
    return ReturnDict(ret, serializer=self)
  File "/usr/local/altschool/vishnu-backend/lib/python2.7/site-packages/rest_framework/utils/serializer_helpers.py", line 20, in __init__
    super(ReturnDict, self).__init__(*args, **kwargs)
  File "/Users/ryochiji/.pyenv/versions/2.7.8/lib/python2.7/collections.py", line 52, in __init__
    self.__update(*args, **kwds)
  File "/usr/local/altschool/vishnu-backend/lib/python2.7/_abcoll.py", line 566, in update
    for key, value in other:
ValueError: too many values to unpack

This seems to happen because Serializer.errors passes self._errors to ReturnDict without type-checking the way ListSerializer.errors does.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      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