#27975 closed Bug (fixed)
Regression on ability to use `queryset=None` on `ModelChoiceField`
| Reported by: | James Beith | Owned by: | nobody |
|---|---|---|---|
| Component: | Forms | Version: | 1.11 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The change in ticket #27563 has unfortunately caused a regression in the ability to use queryset=None on ModelChoiceField and later set the QuerySet in the form's __init__ method.
This functionality is described in Django's documentation.
Please see included patch in the following pull request: #8232
Traceback (most recent call last):
File "/Users/James/Documents/Work/GitHub/django/django/tests/model_forms/tests.py", line 1657, in test_modelchoicefield_queryset_none
form1 = ModelChoiceForm()
File "/Users/James/Documents/Work/GitHub/django/django/tests/model_forms/tests.py", line 1654, in __init__
super().__init__(*args, **kwargs)
File "/Users/James/Documents/Work/GitHub/django/django/django/forms/forms.py", line 96, in __init__
self.fields = copy.deepcopy(self.base_fields)
File "/Users/James/.virtualenvs/django/lib/python3.6/copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/Users/James/.virtualenvs/django/lib/python3.6/copy.py", line 306, in _reconstruct
value = deepcopy(value, memo)
File "/Users/James/.virtualenvs/django/lib/python3.6/copy.py", line 161, in deepcopy
y = copier(memo)
File "/Users/James/Documents/Work/GitHub/django/django/django/forms/models.py", line 1169, in __deepcopy__
result.queryset = self.queryset.all()
AttributeError: 'NoneType' object has no attribute 'all'
Note:
See TracTickets
for help on using tickets.
In 216bb2e: