aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework
diff options
context:
space:
mode:
authorTom Christie2013-10-03 15:18:47 +0100
committerTom Christie2013-10-03 15:18:47 +0100
commitafc9e9e03868634c548178e6730a0f9964f398c0 (patch)
treeac12804aa0ef0cb73a4506177500d0596b2c883a /rest_framework
parentf6301636fb52dc6e02fd55e1c07c0be0a3b4ebfd (diff)
parent38049d11b63cdcc7f2a71ac51600182545912350 (diff)
downloaddjango-rest-framework-afc9e9e03868634c548178e6730a0f9964f398c0.tar.bz2
Merge branch 'master' of https://github.com/tomchristie/django-rest-framework
Diffstat (limited to 'rest_framework')
-rw-r--r--rest_framework/fields.py1
-rw-r--r--rest_framework/tests/test_files.py13
2 files changed, 14 insertions, 0 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py
index 210c2537..0c3817b5 100644
--- a/rest_framework/fields.py
+++ b/rest_framework/fields.py
@@ -306,6 +306,7 @@ class WritableField(Field):
return
try:
+ data = data or {}
if self.use_files:
files = files or {}
try:
diff --git a/rest_framework/tests/test_files.py b/rest_framework/tests/test_files.py
index c13c38b8..78f4cf42 100644
--- a/rest_framework/tests/test_files.py
+++ b/rest_framework/tests/test_files.py
@@ -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())