mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-16 19:41:06 +03:00
Merge pull request #3801 from koordinates/fix-nested-validation-error
Fix nested validation error being rendered incorrectly.
This commit is contained in:
commit
f01a3d9c36
|
@ -306,7 +306,7 @@ def get_validation_error_detail(exc):
|
||||||
# If errors may be a dict we use the standard {key: list of values}.
|
# If errors may be a dict we use the standard {key: list of values}.
|
||||||
# Here we ensure that all the values are *lists* of errors.
|
# Here we ensure that all the values are *lists* of errors.
|
||||||
return {
|
return {
|
||||||
key: value if isinstance(value, list) else [value]
|
key: value if isinstance(value, (list, dict)) else [value]
|
||||||
for key, value in exc.detail.items()
|
for key, value in exc.detail.items()
|
||||||
}
|
}
|
||||||
elif isinstance(exc.detail, list):
|
elif isinstance(exc.detail, list):
|
||||||
|
|
|
@ -49,6 +49,24 @@ class ShouldValidateModelSerializer(serializers.ModelSerializer):
|
||||||
fields = ('renamed',)
|
fields = ('renamed',)
|
||||||
|
|
||||||
|
|
||||||
|
class TestNestedValidationError(TestCase):
|
||||||
|
def test_nested_validation_error_detail(self):
|
||||||
|
"""
|
||||||
|
Ensure nested validation error detail is rendered correctly.
|
||||||
|
"""
|
||||||
|
e = serializers.ValidationError({
|
||||||
|
'nested': {
|
||||||
|
'field': ['error'],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
self.assertEqual(serializers.get_validation_error_detail(e), {
|
||||||
|
'nested': {
|
||||||
|
'field': ['error'],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
class TestPreSaveValidationExclusionsSerializer(TestCase):
|
class TestPreSaveValidationExclusionsSerializer(TestCase):
|
||||||
def test_renamed_fields_are_model_validated(self):
|
def test_renamed_fields_are_model_validated(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user