Skip to content

Commit

Permalink
Merge pull request #3801 from koordinates/fix-nested-validation-error
Browse files Browse the repository at this point in the history
Fix nested validation error being rendered incorrectly.
  • Loading branch information
tomchristie committed Jan 7, 2016
2 parents f7025cf + 651319e commit f01a3d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rest_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def get_validation_error_detail(exc):
# 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.
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()
}
elif isinstance(exc.detail, list):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ class Meta:
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):
def test_renamed_fields_are_model_validated(self):
"""
Expand Down

0 comments on commit f01a3d9

Please sign in to comment.