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
f1bdce17
Commit
f1bdce17
authored
Oct 21, 2016
by
Tom Christie
Committed by
GitHub
Oct 21, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for case of ListSerializer with single item (#4609)
parent
0b346e94
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
rest_framework/serializers.py
+2
-2
tests/test_serializer.py
+13
-0
No files found.
rest_framework/serializers.py
View file @
f1bdce17
...
@@ -507,7 +507,7 @@ class Serializer(BaseSerializer):
...
@@ -507,7 +507,7 @@ class Serializer(BaseSerializer):
@property
@property
def
errors
(
self
):
def
errors
(
self
):
ret
=
super
(
Serializer
,
self
)
.
errors
ret
=
super
(
Serializer
,
self
)
.
errors
if
isinstance
(
ret
,
list
)
and
len
(
ret
)
==
1
and
ret
[
0
]
.
code
==
'null'
:
if
isinstance
(
ret
,
list
)
and
len
(
ret
)
==
1
and
getattr
(
ret
[
0
],
'code'
,
None
)
==
'null'
:
# Edge case. Provide a more descriptive error than
# Edge case. Provide a more descriptive error than
# "this field may not be null", when no data is passed.
# "this field may not be null", when no data is passed.
detail
=
ErrorDetail
(
'No data provided'
,
code
=
'null'
)
detail
=
ErrorDetail
(
'No data provided'
,
code
=
'null'
)
...
@@ -705,7 +705,7 @@ class ListSerializer(BaseSerializer):
...
@@ -705,7 +705,7 @@ class ListSerializer(BaseSerializer):
@property
@property
def
errors
(
self
):
def
errors
(
self
):
ret
=
super
(
ListSerializer
,
self
)
.
errors
ret
=
super
(
ListSerializer
,
self
)
.
errors
if
isinstance
(
ret
,
list
)
and
len
(
ret
)
==
1
and
ret
[
0
]
.
code
==
'null'
:
if
isinstance
(
ret
,
list
)
and
len
(
ret
)
==
1
and
getattr
(
ret
[
0
],
'code'
,
None
)
==
'null'
:
# Edge case. Provide a more descriptive error than
# Edge case. Provide a more descriptive error than
# "this field may not be null", when no data is passed.
# "this field may not be null", when no data is passed.
detail
=
ErrorDetail
(
'No data provided'
,
code
=
'null'
)
detail
=
ErrorDetail
(
'No data provided'
,
code
=
'null'
)
...
...
tests/test_serializer.py
View file @
f1bdce17
...
@@ -357,3 +357,16 @@ class TestSerializerValidationWithCompiledRegexField:
...
@@ -357,3 +357,16 @@ class TestSerializerValidationWithCompiledRegexField:
assert
serializer
.
is_valid
()
assert
serializer
.
is_valid
()
assert
serializer
.
validated_data
==
{
'name'
:
'2'
}
assert
serializer
.
validated_data
==
{
'name'
:
'2'
}
assert
serializer
.
errors
==
{}
assert
serializer
.
errors
==
{}
class
Test4606Regression
:
def
setup
(
self
):
class
ExampleSerializer
(
serializers
.
Serializer
):
name
=
serializers
.
CharField
(
required
=
True
)
choices
=
serializers
.
CharField
(
required
=
True
)
self
.
Serializer
=
ExampleSerializer
def
test_4606_regression
(
self
):
serializer
=
self
.
Serializer
(
data
=
[{
"name"
:
"liz"
}],
many
=
True
)
with
pytest
.
raises
(
serializers
.
ValidationError
):
serializer
.
is_valid
(
raise_exception
=
True
)
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