diff options
author | François Freitag <mail@franek.fr> | 2018-02-23 21:12:09 -0800 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-03-01 14:12:14 -0500 |
commit | 40f0aa988571431508a508f4fac5ba94c6443f5c (patch) | |
tree | a9c32646965d661efb1dc62a8d35f3cc6ed59bb5 /tests/model_forms | |
parent | 06172d7bc29185b7d37fbf62ec3cfdcfcafb4856 (diff) | |
download | django-40f0aa988571431508a508f4fac5ba94c6443f5c.tar.gz |
Fixed #29158 -- Fixed len(choices) crash if ModelChoiceField's queryset is a manager.
Removing all() in __iter__() prevents a duplicate query when choices are
cast to a list and there's a prefetch_related().
Diffstat (limited to 'tests/model_forms')
-rw-r--r-- | tests/model_forms/test_modelchoicefield.py | 1 | ||||
-rw-r--r-- | tests/model_forms/tests.py | 2 |
2 files changed, 2 insertions, 1 deletions
diff --git a/tests/model_forms/test_modelchoicefield.py b/tests/model_forms/test_modelchoicefield.py index 057eb0d25b..6b0f00cf7f 100644 --- a/tests/model_forms/test_modelchoicefield.py +++ b/tests/model_forms/test_modelchoicefield.py @@ -249,6 +249,7 @@ class ModelChoiceFieldTests(TestCase): def test_queryset_manager(self): f = forms.ModelChoiceField(Category.objects) + self.assertEqual(len(f.choices), 4) self.assertEqual(list(f.choices), [ ('', '---------'), (self.c1.pk, 'Entertainment'), diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index fced7403ba..e3c347aee6 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -2339,7 +2339,7 @@ class OtherModelFormTests(TestCase): return ', '.join(c.name for c in obj.colours.all()) field = ColorModelChoiceField(ColourfulItem.objects.prefetch_related('colours')) - with self.assertNumQueries(4): # would be 5 if prefetch is ignored + with self.assertNumQueries(2): # would be 3 if prefetch is ignored self.assertEqual(tuple(field.choices), ( ('', '---------'), (multicolor_item.pk, 'blue, red'), |