Opened 17 years ago

Closed 17 years ago

#4385 closed (fixed)

cleaned_data gets set twice even when no clean_<field> method

Reported by: Thomas Güttler <hv@…> Owned by: Adrian Holovaty
Component: Forms Version: dev
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

newforms/forms.py: (Patch attached)

self.cleaned_data[name] = value
if hasattr(self, 'clean_%s' % name):

value = getattr(self, 'clean_%s' % name)()

self.cleaned_data[name] = value

Attachments (2)

settingtwice.diff (575 bytes ) - added by Thomas Güttler <hv@…> 17 years ago.
4385.diff (542 bytes ) - added by Gary Wilson <gary.wilson@…> 17 years ago.
Only assign to cleaned_data again if we had a clean_<field> method.

Download all attachments as: .zip

Change History (9)

by Thomas Güttler <hv@…>, 17 years ago

Attachment: settingtwice.diff added

comment:1 by anonymous, 17 years ago

Doesn't the clean_ method need access to clean_data containing the cleaned value?

comment:2 by Thomas Güttler <hv@…>, 17 years ago

Yes, you are right. But a comment in the code would be good. Otherwise
this line looks like a typo.

comment:3 by Marc Fargas <telenieko@…>, 17 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Gary Wilson <gary.wilson@…>, 17 years ago

Yes, this needs to happen twice since the clean_<field> method needs access to the field's value in cleaned_data, however it looks like the second assignment could be moved inside the if statement. That way, it's only set twice if there is a clean_<field> method for the field.

by Gary Wilson <gary.wilson@…>, 17 years ago

Attachment: 4385.diff added

Only assign to cleaned_data again if we had a clean_<field> method.

comment:5 by Gary Wilson <gary.wilson@…>, 17 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Gary Wilson <gary.wilson@…>, 17 years ago

Summary: Typo: value gets set twicecleaned_data gets set twice even when no clean_<field> method

comment:7 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: newclosed

(In [5346]) Fixed #4390, #4385 -- Made it clear that cleaned_data wasn't being assigned to
twice without reason. Also make sure that if field specific clean functions
fail, the form-wide field cleaning is removed from cleaned_data.

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