mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
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().
This commit is contained in:
parent
06172d7bc2
commit
40f0aa9885
3 changed files with 4 additions and 3 deletions
|
@ -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'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue