Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
f01a3d9c
Commit
f01a3d9c
authored
Jan 07, 2016
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3801 from koordinates/fix-nested-validation-error
Fix nested validation error being rendered incorrectly.
parents
f7025cf5
651319e2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletions
+19
-1
rest_framework/serializers.py
+1
-1
tests/test_validation.py
+18
-0
No files found.
rest_framework/serializers.py
View file @
f01a3d9c
...
@@ -306,7 +306,7 @@ def get_validation_error_detail(exc):
...
@@ -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
):
...
...
tests/test_validation.py
View file @
f01a3d9c
...
@@ -49,6 +49,24 @@ class ShouldValidateModelSerializer(serializers.ModelSerializer):
...
@@ -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
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment