[Django] #25085: Select Widget's __deepcopy__ does not copy its choices.

20 views
Skip to first unread message

Django

unread,
Jul 8, 2015, 6:58:44 PM7/8/15
to django-...@googlegroups.com
#25085: Select Widget's __deepcopy__ does not copy its choices.
-------------------------+-------------------------------------------------
Reporter: ericfc | Owner:
Type: Bug | Status: new
Component: Forms | Version: 1.8
Severity: Normal | Keywords: Select Widget deepcopy __deepcopy__
Triage Stage: | choices
Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------------------
Select inherits its parent's (Widget's) __deepcopy__ which does not take
into consideration its choices field and we get weird behavior like below:

{{{
from django import forms

class Fields(forms.Form):
field = forms.ChoiceField(choices=(('one', 'one'), ('two', 'two')))

class Foo(Fields):
def __init__(self, *args, **kwargs):
super(Foo, self).__init__(*args, **kwargs)
self.fields['field'].widget.choices[0] = ('foo', 'foo')

class Bar(Fields):
pass

foo = Foo()
bar = Bar()

foo.fields['field'].widget.choices
>>>[('foo', 'foo'), ('two', 'two')]

bar.fields['field'].widget.choices
>>>[('foo', 'foo'), ('two', 'two')]
}}}

Where foo and bar have nothing to do with one another.
A more simple example:
{{{
import copy
from django import forms

widget = forms.Select()
widget_copy = copy.deepcopy(widget)

widget.attrs is widget_copy.attrs
>>>False
widget.choices is widget_copy.choices
>>>True
}}}
Since we did a deepcopy the {{widget.choices is widget_copy.choices}}}
must have returned {{False}} yet it returned {{{True}}}.

--
Ticket URL: <https://code.djangoproject.com/ticket/25085>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 8, 2015, 6:59:00 PM7/8/15
to django-...@googlegroups.com
#25085: Select Widget's __deepcopy__ does not copy its choices.
-------------------------------------+-------------------------------------
Reporter: ericfc | Owner: ericfc
Type: Bug | Status: assigned
Component: Forms | Version: 1.8
Severity: Normal | Resolution:
Keywords: Select Widget | Triage Stage:
deepcopy __deepcopy__ choices | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ericfc):

* status: new => assigned
* needs_docs: => 0
* owner: => ericfc
* needs_tests: => 0
* needs_better_patch: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25085#comment:1>

Django

unread,
Jul 8, 2015, 8:08:14 PM7/8/15
to django-...@googlegroups.com
#25085: Select Widget's __deepcopy__ does not copy its choices.
-------------------------------------+-------------------------------------
Reporter: ericfc | Owner: ericfc
Type: Bug | Status: assigned
Component: Forms | Version: 1.8

Severity: Normal | Resolution:
Keywords: Select Widget | Triage Stage:
deepcopy __deepcopy__ choices | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ericfc):

* Attachment "25085.diff" added.

Django

unread,
Jul 8, 2015, 8:08:52 PM7/8/15
to django-...@googlegroups.com
#25085: Select Widget's __deepcopy__ does not copy its choices.
-------------------------------------+-------------------------------------
Reporter: ericfc | Owner: ericfc
Type: Bug | Status: assigned
Component: Forms | Version: 1.8

Severity: Normal | Resolution:
Keywords: Select Widget | Triage Stage:
deepcopy __deepcopy__ choices | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by ericfc):

The pull request has been made:
https://github.com/django/django/pull/4965

--
Ticket URL: <https://code.djangoproject.com/ticket/25085#comment:2>

Django

unread,
Jul 8, 2015, 9:01:28 PM7/8/15
to django-...@googlegroups.com
#25085: Select Widget's __deepcopy__ does not copy its choices.
-------------------------------------+-------------------------------------
Reporter: ericfc | Owner: ericfc
Type: Bug | Status: assigned
Component: Forms | Version: 1.8

Severity: Normal | Resolution:
Keywords: Select Widget | Triage Stage:
deepcopy __deepcopy__ choices | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by ericfc:

Old description:

New description:

{{{
from django import forms

class Bar(Fields):
pass

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25085#comment:3>

Django

unread,
Jul 10, 2015, 10:29:18 AM7/10/15
to django-...@googlegroups.com
#25085: Select Widget's __deepcopy__ does not copy its choices.
-------------------------------------+-------------------------------------
Reporter: ericfc | Owner: ericfc
Type: Bug | Status: assigned
Component: Forms | Version: 1.8
Severity: Normal | Resolution:
Keywords: Select Widget | Triage Stage: Accepted
deepcopy __deepcopy__ choices |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25085#comment:4>

Django

unread,
Jul 14, 2015, 9:47:44 AM7/14/15
to django-...@googlegroups.com
#25085: Select Widget's __deepcopy__ does not copy its choices.
-------------------------------------+-------------------------------------
Reporter: ericfc | Owner: ericfc
Type: Bug | Status: assigned
Component: Forms | Version: 1.8
Severity: Normal | Resolution:
Keywords: Select Widget | Triage Stage: Ready for
deepcopy __deepcopy__ choices | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/25085#comment:5>

Django

unread,
Jul 14, 2015, 11:56:29 AM7/14/15
to django-...@googlegroups.com
#25085: Select Widget's __deepcopy__ does not copy its choices.
-------------------------------------+-------------------------------------
Reporter: ericfc | Owner: ericfc
Type: Bug | Status: closed
Component: Forms | Version: 1.8
Severity: Normal | Resolution: fixed

Keywords: Select Widget | Triage Stage: Ready for
deepcopy __deepcopy__ choices | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"8ee6a3f1a855bf983639a14fc2393baa8ead741f" 8ee6a3f]:
{{{
#!CommitTicketReference repository=""
revision="8ee6a3f1a855bf983639a14fc2393baa8ead741f"
Fixed #25085 -- Overrode Select widget's __deepcopy__()
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25085#comment:6>

Django

unread,
Jul 14, 2015, 12:18:27 PM7/14/15
to django-...@googlegroups.com
#25085: Select Widget's __deepcopy__ does not copy its choices.
-------------------------------------+-------------------------------------
Reporter: ericfc | Owner: ericfc
Type: Bug | Status: closed
Component: Forms | Version: 1.8

Severity: Normal | Resolution: fixed
Keywords: Select Widget | Triage Stage: Ready for
deepcopy __deepcopy__ choices | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"b356dc4e07915521db1e768d6357e3d982877a6e" b356dc4e]:
{{{
#!CommitTicketReference repository=""
revision="b356dc4e07915521db1e768d6357e3d982877a6e"
Refs #25085 -- Used more specific assertion in widget test.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25085#comment:7>

Reply all
Reply to author
Forward
0 new messages