f = TestForm()
f.fields['field1'].choices = [("1", "1")]
f.fields['field2'].choices = [("2", "2")]
assert f.fields['field1'].widget.choices == [("1", "1")]
assert f.fields['field2'].widget.choices == [("2", "2")]
}}}
I took a deep dive, and found out that since the field instances
themselves share the widget instance (as it's a class attribute that
doesn't need to get instantiated in each field instance), when fields are
getting deepcopied in `BaseForm.__init__`, their copies all share one new
copy of the widget instance.
This is quite easy to fix by deepcopying the widget in the case where it
was specified as an instance, rather than a widget class. Patch coming up
in a couple of minutes.
--
Ticket URL: <https://code.djangoproject.com/ticket/27369>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* has_patch: 0 => 1
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27369#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/27369#comment:2>
Comment (by Jaap Roes):
Replying to [comment:1 Michal Petrucha]:
> [https://github.com/django/django/pull/6267 PR]
This links to the wrong PR (#6267), the correct one is this
[https://github.com/django/django/pull/7415 PR #7415]
--
Ticket URL: <https://code.djangoproject.com/ticket/27369#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/27369#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"09da1e79de5a03a63610822bd4e5fc2adcbeb38a" 09da1e79]:
{{{
#!CommitTicketReference repository=""
revision="09da1e79de5a03a63610822bd4e5fc2adcbeb38a"
Fixed #27369 -- Prevented widgets from being shared between form field
instances.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27369#comment:4>