mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 13:14:30 +03:00
Merge pull request #1104 from FreakyDug/master
Fix a TypeError when a serializer is created with files but no data
This commit is contained in:
commit
38049d11b6
|
@ -306,6 +306,7 @@ class WritableField(Field):
|
|||
return
|
||||
|
||||
try:
|
||||
data = data or {}
|
||||
if self.use_files:
|
||||
files = files or {}
|
||||
try:
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue
Block a user