mirror of https://github.com/django/django.git
Fixed #27975 -- Fixed crash if ModelChoiceField's queryset=None.
Regression in 9153d8fbd6385db9f48793662de789fc3d686841.
This commit is contained in:
parent
325db2a8c3
commit
216bb2e8fb
|
@ -1155,7 +1155,8 @@ class ModelChoiceField(ChoiceField):
|
||||||
def __deepcopy__(self, memo):
|
def __deepcopy__(self, memo):
|
||||||
result = super(ChoiceField, self).__deepcopy__(memo)
|
result = super(ChoiceField, self).__deepcopy__(memo)
|
||||||
# Need to force a new ModelChoiceIterator to be created, bug #11183
|
# Need to force a new ModelChoiceIterator to be created, bug #11183
|
||||||
result.queryset = self.queryset.all()
|
if self.queryset is not None:
|
||||||
|
result.queryset = self.queryset.all()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _get_queryset(self):
|
def _get_queryset(self):
|
||||||
|
|
|
@ -1640,6 +1640,17 @@ class ModelChoiceFieldTests(TestCase):
|
||||||
form2 = ModelChoiceForm()
|
form2 = ModelChoiceForm()
|
||||||
self.assertIsNone(form2.fields['category'].queryset._result_cache)
|
self.assertIsNone(form2.fields['category'].queryset._result_cache)
|
||||||
|
|
||||||
|
def test_modelchoicefield_queryset_none(self):
|
||||||
|
class ModelChoiceForm(forms.Form):
|
||||||
|
category = forms.ModelChoiceField(queryset=None)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(ModelChoiceForm, self).__init__(*args, **kwargs)
|
||||||
|
self.fields['category'].queryset = Category.objects.filter(slug__contains='test')
|
||||||
|
|
||||||
|
form = ModelChoiceForm()
|
||||||
|
self.assertCountEqual(form.fields['category'].queryset, [self.c2, self.c3])
|
||||||
|
|
||||||
def test_modelchoicefield_22745(self):
|
def test_modelchoicefield_22745(self):
|
||||||
"""
|
"""
|
||||||
#22745 -- Make sure that ModelChoiceField with RadioSelect widget
|
#22745 -- Make sure that ModelChoiceField with RadioSelect widget
|
||||||
|
|
Loading…
Reference in New Issue