Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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'

Change History (2)

comment:1 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 216bb2e:

Fixed #27975 -- Fixed crash if ModelChoiceField's queryset=None.

Regression in 9153d8fbd6385db9f48793662de789fc3d686841.

comment:2 by Tim Graham <timograham@…>, 8 years ago

In 6963564e:

[1.11.x] Fixed #27975 -- Fixed crash if ModelChoiceField's queryset=None.

Regression in 9153d8fbd6385db9f48793662de789fc3d686841.

Backport of 216bb2e8fbc3cb37615bbd70edaa73287acdca81 from master

Note: See TracTickets for help on using tickets.
Back to Top