Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#25683 closed Bug (fixed)

1.8.6 regression: ModelChoiceField no longer accepts Manager objects as queryset

Reported by: Marti Raudsepp Owned by: nobody
Component: Forms Version: 1.8
Severity: Release blocker Keywords:
Cc: Tim Graham, marti@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi! It seems that the fix for #25496 caused a regression. When one uses ModelChoiceField(queryset=FooModel.objects) then it throws:

Traceback (most recent call last):
  File "/home/marti/workspace/django/tests/forms_tests/tests/tests.py", line 93, in test_modelchoicefield_manager
    self.assertTrue(list(f.choices))
  File "/home/marti/workspace/django/django/forms/models.py", line 1095, in __iter__
    method = 'all' if self.queryset._prefetch_related_lookups else 'iterator'
AttributeError: 'Manager' object has no attribute '_prefetch_related_lookups'

I have a patch in development to fix this, should be ready soon.

Change History (5)

comment:1 Changed 4 years ago by Marti Raudsepp

Cc: marti@… added
Version 0, edited 4 years ago by Marti Raudsepp (next)

comment:2 Changed 4 years ago by Iacopo Spalletti

Triage Stage: UnreviewedAccepted

Proposed test raise the reported issue and the code fix fixes the test

Last edited 4 years ago by Iacopo Spalletti (previous) (diff)

comment:3 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 1155843a:

Fixed #25683 -- Allowed ModelChoiceField(queryset=...) to accept Managers.

This fixes a regression from refs #25496.

comment:5 Changed 4 years ago by Tim Graham <timograham@…>

In 8db5122d:

[1.9.x] Fixed #25683 -- Allowed ModelChoiceField(queryset=...) to accept Managers.

This fixes a regression from refs #25496.

Backport of 1155843a41af589a856efe8e671a796866430049 from master

comment:4 Changed 4 years ago by Tim Graham <timograham@…>

In 3144785:

[1.8.x] Fixed #25683 -- Allowed ModelChoiceField(queryset=...) to accept Managers.

This fixes a regression from refs #25496.

Backport of 1155843a41af589a856efe8e671a796866430049 from master

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