Opened 12 years ago
Closed 11 years ago
#19298 closed Bug (fixed)
MultiValueField should override __deepcopy__
Reported by: | 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)
Change History (6)
comment:1 by , 12 years ago
Cc: | added |
---|
comment:2 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 11 years ago
Attachment: | deepcopy_multivaluefields.patch added |
---|
comment:3 by , 11 years ago
comment:4 by , 11 years ago
Easy pickings: | set |
---|---|
Has patch: | set |
comment:5 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Attached patch makes sure deepcopy is called on all the sub fields