mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-31 18:40:07 +03:00
Avoid suppressing custom ValidationError
Solution for a specific case, when detail of ValidationError is dictionary already. closes https://github.com/encode/django-rest-framework/issues/6124
This commit is contained in:
parent
90ed2c1ef7
commit
770b912a88
|
@ -235,6 +235,8 @@ class BaseSerializer(Field):
|
|||
try:
|
||||
self._validated_data = self.run_validation(self.initial_data)
|
||||
except ValidationError as exc:
|
||||
if isinstance(exc.detail, dict):
|
||||
raise
|
||||
self._validated_data = {}
|
||||
self._errors = exc.detail
|
||||
else:
|
||||
|
@ -489,6 +491,8 @@ class Serializer(BaseSerializer):
|
|||
if validate_method is not None:
|
||||
validated_value = validate_method(validated_value)
|
||||
except ValidationError as exc:
|
||||
if isinstance(exc.detail, dict):
|
||||
raise
|
||||
errors[field.field_name] = exc.detail
|
||||
except DjangoValidationError as exc:
|
||||
errors[field.field_name] = get_error_detail(exc)
|
||||
|
@ -661,6 +665,8 @@ class ListSerializer(BaseSerializer):
|
|||
try:
|
||||
validated = self.child.run_validation(item)
|
||||
except ValidationError as exc:
|
||||
if isinstance(exc.detail, dict):
|
||||
raise
|
||||
errors.append(exc.detail)
|
||||
else:
|
||||
ret.append(validated)
|
||||
|
@ -744,6 +750,8 @@ class ListSerializer(BaseSerializer):
|
|||
try:
|
||||
self._validated_data = self.run_validation(self.initial_data)
|
||||
except ValidationError as exc:
|
||||
if isinstance(exc.detail, dict):
|
||||
raise
|
||||
self._validated_data = []
|
||||
self._errors = exc.detail
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user