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
51e69823
Commit
51e69823
authored
Mar 06, 2014
by
Xavier Ordoquy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed the validation for optional fields that have a value.
parent
caf4d36c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
rest_framework/serializers.py
+3
-3
No files found.
rest_framework/serializers.py
View file @
51e69823
...
@@ -881,7 +881,7 @@ class ModelSerializer(Serializer):
...
@@ -881,7 +881,7 @@ class ModelSerializer(Serializer):
except
KeyError
:
except
KeyError
:
return
ModelField
(
model_field
=
model_field
,
**
kwargs
)
return
ModelField
(
model_field
=
model_field
,
**
kwargs
)
def
get_validation_exclusions
(
self
):
def
get_validation_exclusions
(
self
,
instance
=
None
):
"""
"""
Return a list of field names to exclude from model validation.
Return a list of field names to exclude from model validation.
"""
"""
...
@@ -893,7 +893,7 @@ class ModelSerializer(Serializer):
...
@@ -893,7 +893,7 @@ class ModelSerializer(Serializer):
field_name
=
field
.
source
or
field_name
field_name
=
field
.
source
or
field_name
if
field_name
in
exclusions
\
if
field_name
in
exclusions
\
and
not
field
.
read_only
\
and
not
field
.
read_only
\
and
field
.
required
\
and
(
field
.
required
or
hasattr
(
instance
,
field_name
))
\
and
not
isinstance
(
field
,
Serializer
):
and
not
isinstance
(
field
,
Serializer
):
exclusions
.
remove
(
field_name
)
exclusions
.
remove
(
field_name
)
return
exclusions
return
exclusions
...
@@ -908,7 +908,7 @@ class ModelSerializer(Serializer):
...
@@ -908,7 +908,7 @@ class ModelSerializer(Serializer):
the full_clean validation checking.
the full_clean validation checking.
"""
"""
try
:
try
:
instance
.
full_clean
(
exclude
=
self
.
get_validation_exclusions
())
instance
.
full_clean
(
exclude
=
self
.
get_validation_exclusions
(
instance
))
except
ValidationError
as
err
:
except
ValidationError
as
err
:
self
.
_errors
=
err
.
message_dict
self
.
_errors
=
err
.
message_dict
return
None
return
None
...
...
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