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,10 +174,16 @@ 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):
|
||||||
|
field = models.IntegerField(choices=[0])
|
||||||
|
|
||||||
|
for model in (Model, Model2):
|
||||||
|
with self.subTest(model.__name__):
|
||||||
|
field = model._meta.get_field('field')
|
||||||
self.assertEqual(field.check(), [
|
self.assertEqual(field.check(), [
|
||||||
Error(
|
Error(
|
||||||
"'choices' must be an iterable containing (actual value, human readable name) tuples.",
|
"'choices' must be an iterable containing (actual "
|
||||||
|
"value, human readable name) tuples.",
|
||||||
obj=field,
|
obj=field,
|
||||||
id='fields.E005',
|
id='fields.E005',
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue