Fixed #23098 -- Checked that lazy choices are not evaluated too soon

Thanks Matthieu Agopian for the report.
This commit is contained in:
Florian Apolloner 2014-07-25 19:20:00 +02:00
parent 2ab0ed7b28
commit 2f73b527dd
2 changed files with 13 additions and 4 deletions

View file

@ -416,6 +416,13 @@ class ValidationTest(test.TestCase):
f = models.CharField(choices=[('', '<><>'), ('a', 'A')])
self.assertEqual(f.get_choices(True), [('', '<><>'), ('a', 'A')])
def test_charfield_get_choices_doesnt_evaluate_lazy_strings(self):
# Regression test for #23098
# Will raise ZeroDivisionError if lazy is evaluated
lazy_func = lazy(lambda x: 0/0, int)
f = models.CharField(choices=[(lazy_func('group'), (('a', 'A'), ('b', 'B')))])
self.assertEqual(f.get_choices(True)[0], ('', '---------'))
def test_choices_validation_supports_named_groups(self):
f = models.IntegerField(
choices=(('group', ((10, 'A'), (20, 'B'))), (30, 'C')))