ValidationError(str) should default to a dict not list

ValidationError(str) should use the api_settings. NON_FIELD_ERRORS_KEY and make a dict, not default to a list.
This commit is contained in:
Mark Davidoff 2018-03-29 17:00:12 -07:00 committed by GitHub
parent 489d3415ab
commit 8cf8765b6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,7 +16,7 @@ from django.utils.translation import ungettext
from rest_framework import status from rest_framework import status
from rest_framework.compat import unicode_to_repr from rest_framework.compat import unicode_to_repr
from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList
from rest_framework.settings import api_settings
def _get_error_details(data, default_code=None): def _get_error_details(data, default_code=None):
""" """
@ -149,7 +149,7 @@ class ValidationError(APIException):
# For validation failures, we may collect many errors together, # For validation failures, we may collect many errors together,
# so the details should always be coerced to a list if not already. # so the details should always be coerced to a list if not already.
if not isinstance(detail, dict) and not isinstance(detail, list): if not isinstance(detail, dict) and not isinstance(detail, list):
detail = [detail] detail = { api_settings.NON_FIELD_ERRORS_KEY: detail }
self.detail = _get_error_details(detail, code) self.detail = _get_error_details(detail, code)