summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2014-07-25 19:20:00 +0200
committerFlorian Apolloner <florian@apolloner.eu>2014-07-27 13:31:25 +0200
commit2f73b527dda6683868fac2791f7f07ccb01ea0d9 (patch)
tree45588c0291a73bc6197956c06026c76116e1d630 /tests
parent2ab0ed7b2842fbb8bf36ee7df9949d10546d953d (diff)
Fixed #23098 -- Checked that lazy choices are not evaluated too soon
Thanks Matthieu Agopian for the report.
Diffstat (limited to 'tests')
-rw-r--r--tests/model_fields/tests.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py
index b33314bfd3..87236c31d5 100644
--- a/tests/model_fields/tests.py
+++ b/tests/model_fields/tests.py
@@ -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')))