Opened 12 years ago

Closed 11 years ago

#19298 closed Bug (fixed)

MultiValueField should override __deepcopy__

Reported by: nick.phillips@… Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: nwp Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

MultiValueField needs to override the default inherited from Field, as it needs to deep-copy subfields:

    def __deepcopy__(self, memo):
        result = copy.copy(self)
        memo[id(self)] = result
        result.fields = copy.deepcopy(self.fields, memo)
        result.widget = copy.deepcopy(self.widget, memo)
        result.validators = self.validators[:]
        return result

or

    def __deepcopy__(self, memo):
        result = super(MultiValueField, self).__deepcopy__(memo)
        result.fields = copy.deepcopy(self.fields, memo)
        return result

should be added to MultiValueField, if I'm right.

Without this, any "MyClass" that subclasses MultiValueField and uses subfields with complex attributes (e.g. ChoiceField's "choices") will fail when re-used within the same view.

Attachments (1)

deepcopy_multivaluefields.patch (1.9 KB ) - added by anonymous 11 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by nwp, 12 years ago

Cc: nwp added

comment:2 by Claude Paroz, 12 years ago

Triage Stage: UnreviewedAccepted

by anonymous, 11 years ago

comment:3 by anonymous, 11 years ago

Attached patch makes sure deepcopy is called on all the sub fields

comment:4 by anonymous, 11 years ago

Easy pickings: set
Has patch: set

comment:5 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 4e96dac450e3546bf86220932f5a64fea1ad5bac:

Fixed #19298 -- Added MultiValueField.deepcopy

Thanks nick.phillips at otago.ac.nz for the report.

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