Fixed #28120 -- Checked that CharField.max_length is not a boolean.

This commit is contained in:
Carles Pina Estany 2017-04-25 00:49:31 +02:00 committed by Simon Charette
parent 851874fe0a
commit 9f2e8b5bb7
3 changed files with 18 additions and 1 deletions

View File

@ -140,6 +140,7 @@ answer newbie questions, and generally made Django that much better:
Cameron Knight (ckknight)
Can Burak Çilingir <canburak@cs.bilgi.edu.tr>
Carl Meyer <carl@oddbird.net>
Carles Pina i Estany <carles@pina.cat>
Carlos Eduardo de Paula <carlosedp@gmail.com>
Carlos Matías de la Torre <cmdelatorre@gmail.com>
Carlton Gibson <carlton.gibson@noumenal.es>

View File

@ -1040,7 +1040,8 @@ class CharField(Field):
id='fields.E120',
)
]
elif not isinstance(self.max_length, int) or self.max_length <= 0:
elif (not isinstance(self.max_length, int) or isinstance(self.max_length, bool) or
self.max_length <= 0):
return [
checks.Error(
"'max_length' must be a positive integer.",

View File

@ -139,6 +139,21 @@ class CharFieldTests(TestCase):
]
self.assertEqual(errors, expected)
def test_str_max_length_type(self):
class Model(models.Model):
field = models.CharField(max_length=True)
field = Model._meta.get_field('field')
errors = field.check()
expected = [
Error(
"'max_length' must be a positive integer.",
obj=field,
id='fields.E121'
),
]
self.assertEqual(errors, expected)
def test_non_iterable_choices(self):
class Model(models.Model):
field = models.CharField(max_length=10, choices='bad')