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
38049d11
Commit
38049d11
authored
Oct 03, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1104 from FreakyDug/master
Fix a TypeError when a serializer is created with files but no data
parents
c3175900
a2ae469f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
+14
-0
rest_framework/fields.py
+1
-0
rest_framework/tests/test_files.py
+13
-0
No files found.
rest_framework/fields.py
View file @
38049d11
...
...
@@ -306,6 +306,7 @@ class WritableField(Field):
return
try
:
data
=
data
or
{}
if
self
.
use_files
:
files
=
files
or
{}
try
:
...
...
rest_framework/tests/test_files.py
View file @
38049d11
...
...
@@ -80,3 +80,16 @@ class FileSerializerTests(TestCase):
serializer
=
UploadedFileSerializer
(
data
=
{
'created'
:
now
,
'file'
:
'abc'
})
self
.
assertFalse
(
serializer
.
is_valid
())
self
.
assertEqual
(
serializer
.
errors
,
{
'file'
:
[
errmsg
]})
def
test_validation_with_no_data
(
self
):
"""
Validation should still function when no data dictionary is provided.
"""
now
=
datetime
.
datetime
.
now
()
file
=
BytesIO
(
six
.
b
(
'stuff'
))
file
.
name
=
'stuff.txt'
file
.
size
=
len
(
file
.
getvalue
())
uploaded_file
=
UploadedFile
(
file
=
file
,
created
=
now
)
serializer
=
UploadedFileSerializer
(
files
=
{
'file'
:
file
})
self
.
assertFalse
(
serializer
.
is_valid
())
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