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
a5f822d0
Commit
a5f822d0
authored
Jun 08, 2016
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Empty cases of .validated_data and .errors as lists not dicts for ListSerializer (#4180)
parent
04e5b5b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
rest_framework/serializers.py
+22
-0
tests/test_serializer_bulk_update.py
+2
-0
No files found.
rest_framework/serializers.py
View file @
a5f822d0
...
...
@@ -667,6 +667,28 @@ class ListSerializer(BaseSerializer):
return
self
.
instance
def
is_valid
(
self
,
raise_exception
=
False
):
# This implementation is the same as the default,
# except that we use lists, rather than dicts, as the empty case.
assert
hasattr
(
self
,
'initial_data'
),
(
'Cannot call `.is_valid()` as no `data=` keyword argument was '
'passed when instantiating the serializer instance.'
)
if
not
hasattr
(
self
,
'_validated_data'
):
try
:
self
.
_validated_data
=
self
.
run_validation
(
self
.
initial_data
)
except
ValidationError
as
exc
:
self
.
_validated_data
=
[]
self
.
_errors
=
exc
.
detail
else
:
self
.
_errors
=
[]
if
self
.
_errors
and
raise_exception
:
raise
ValidationError
(
self
.
errors
)
return
not
bool
(
self
.
_errors
)
def
__repr__
(
self
):
return
unicode_to_repr
(
representation
.
list_repr
(
self
,
indent
=
1
))
...
...
tests/test_serializer_bulk_update.py
View file @
a5f822d0
...
...
@@ -46,6 +46,7 @@ class BulkCreateSerializerTests(TestCase):
serializer
=
self
.
BookSerializer
(
data
=
data
,
many
=
True
)
self
.
assertEqual
(
serializer
.
is_valid
(),
True
)
self
.
assertEqual
(
serializer
.
validated_data
,
data
)
self
.
assertEqual
(
serializer
.
errors
,
[])
def
test_bulk_create_errors
(
self
):
"""
...
...
@@ -76,6 +77,7 @@ class BulkCreateSerializerTests(TestCase):
serializer
=
self
.
BookSerializer
(
data
=
data
,
many
=
True
)
self
.
assertEqual
(
serializer
.
is_valid
(),
False
)
self
.
assertEqual
(
serializer
.
errors
,
expected_errors
)
self
.
assertEqual
(
serializer
.
validated_data
,
[])
def
test_invalid_list_datatype
(
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