Opened 3 years ago

Closed 23 months 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

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

Download all attachments as: .zip

Change History (6)

comment:1 Changed 3 years ago by nwp

  • Cc nwp added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 3 years ago by claudep

  • Triage Stage changed from Unreviewed to Accepted

Changed 2 years ago by anonymous

comment:3 Changed 2 years ago by anonymous

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

comment:4 Changed 2 years ago by anonymous

  • Easy pickings set
  • Has patch set

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

  • Resolution set to fixed
  • Status changed from new to closed

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