Opened 6 years ago

Closed 5 years ago

#19298 closed Bug (fixed)

MultiValueField should override __deepcopy__

Reported by: nick.phillips@… Owned by: nobody
Component: Forms Version: master
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


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


    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 5 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by nwp

Cc: nwp added

comment:2 Changed 6 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted

Changed 5 years ago by anonymous

comment:3 Changed 5 years ago by anonymous

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

comment:4 Changed 5 years ago by anonymous

Easy pickings: set
Has patch: set

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

Resolution: fixed
Status: newclosed

In 4e96dac450e3546bf86220932f5a64fea1ad5bac:

Fixed #19298 -- Added MultiValueField.deepcopy

Thanks nick.phillips at for the report.

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