Refs #27358 -- Fixed system check crash with an empty FileField.upload_to.

This commit is contained in:
Lex Berezhny 2016-11-30 09:11:44 -05:00 committed by Tim Graham
parent ddf169cdac
commit 1a9bd75bfa
2 changed files with 7 additions and 1 deletions

View File

@ -256,7 +256,7 @@ class FileField(Field):
return [] return []
def _check_upload_to(self): def _check_upload_to(self):
if isinstance(self.upload_to, six.string_types) and self.upload_to[0] == '/': if isinstance(self.upload_to, six.string_types) and self.upload_to.startswith('/'):
return [ return [
checks.Error( checks.Error(
"%s's 'upload_to' argument must be a relative path, not an " "%s's 'upload_to' argument must be a relative path, not an "

View File

@ -431,6 +431,12 @@ class DecimalFieldTests(SimpleTestCase):
@isolate_apps('invalid_models_tests') @isolate_apps('invalid_models_tests')
class FileFieldTests(SimpleTestCase): class FileFieldTests(SimpleTestCase):
def test_valid_default_case(self):
class Model(models.Model):
field = models.FileField()
self.assertEqual(Model._meta.get_field('field').check(), [])
def test_valid_case(self): def test_valid_case(self):
class Model(models.Model): class Model(models.Model):
field = models.FileField(upload_to='somewhere') field = models.FileField(upload_to='somewhere')