diff options
| author | Carles Pina Estany <carles@pina.cat> | 2017-04-25 00:49:31 +0200 |
|---|---|---|
| committer | Simon Charette <charettes@users.noreply.github.com> | 2017-04-24 18:49:31 -0400 |
| commit | 9f2e8b5bb79722ccafa3c4d6816bc847be1f59f9 (patch) | |
| tree | f6e69ec4554224ef393dc1cf05f39ff153e606c2 | |
| parent | 851874fe0a5dd8f99c763134df0bbaca6f03d17a (diff) | |
Fixed #28120 -- Checked that CharField.max_length is not a boolean.
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | django/db/models/fields/__init__.py | 3 | ||||
| -rw-r--r-- | tests/invalid_models_tests/test_ordinary_fields.py | 15 |
3 files changed, 18 insertions, 1 deletions
@@ -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> diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 77117009ab..95630ebb4e 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -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.", diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py index 9b5b57834d..90f4b31902 100644 --- a/tests/invalid_models_tests/test_ordinary_fields.py +++ b/tests/invalid_models_tests/test_ordinary_fields.py @@ -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') |
