﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27369	Multiple form fields can share the same widget instance	Michal Petrucha	Michal Petrucha	"Say we have a custom form field that defines a certain HTML class on its widget:
{{{#!python
class CustomChoiceField(ChoiceField):
    widget = Select(attrs={'class': 'my-custom-class'})
}}}
If this field type is used for multiple fields in the same form, they will all share the same widget instance. This leads to conflicts when setting the fields' choices; since they all use the same widget instance, all fields will render the same choices from the widget even though the fields themselves might have different choices. The following test case fails, for example:
{{{#!python
class TestForm(Form):
    field1 = CustomChoiceField(choices=[])
    field2 = CustomChoiceField(choices=[])

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."	Bug	closed	Forms	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
