Fixed #29698 -- Fixed Field._check_choices() crash on invalid choices.
This commit is contained in:
parent
50b8493581
commit
7def8bed58
|
@ -260,7 +260,7 @@ class Field(RegisterLookupMixin):
|
||||||
for choices_group in self.choices:
|
for choices_group in self.choices:
|
||||||
try:
|
try:
|
||||||
group_name, group_choices = choices_group
|
group_name, group_choices = choices_group
|
||||||
except ValueError:
|
except (TypeError, ValueError):
|
||||||
# Containing non-pairs
|
# Containing non-pairs
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -174,14 +174,20 @@ class CharFieldTests(TestCase):
|
||||||
class Model(models.Model):
|
class Model(models.Model):
|
||||||
field = models.CharField(max_length=10, choices=[(1, 2, 3), (1, 2, 3)])
|
field = models.CharField(max_length=10, choices=[(1, 2, 3), (1, 2, 3)])
|
||||||
|
|
||||||
field = Model._meta.get_field('field')
|
class Model2(models.Model):
|
||||||
self.assertEqual(field.check(), [
|
field = models.IntegerField(choices=[0])
|
||||||
Error(
|
|
||||||
"'choices' must be an iterable containing (actual value, human readable name) tuples.",
|
for model in (Model, Model2):
|
||||||
obj=field,
|
with self.subTest(model.__name__):
|
||||||
id='fields.E005',
|
field = model._meta.get_field('field')
|
||||||
),
|
self.assertEqual(field.check(), [
|
||||||
])
|
Error(
|
||||||
|
"'choices' must be an iterable containing (actual "
|
||||||
|
"value, human readable name) tuples.",
|
||||||
|
obj=field,
|
||||||
|
id='fields.E005',
|
||||||
|
),
|
||||||
|
])
|
||||||
|
|
||||||
def test_choices_containing_lazy(self):
|
def test_choices_containing_lazy(self):
|
||||||
class Model(models.Model):
|
class Model(models.Model):
|
||||||
|
|
Loading…
Reference in New Issue