Opened 10 years ago

Closed 10 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: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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@…> 10 years ago.
4385.diff (542 bytes) - added by Gary Wilson <gary.wilson@…> 10 years ago.
Only assign to cleaned_data again if we had a clean_<field> method.

Download all attachments as: .zip

Change History (9)

Changed 10 years ago by Thomas Güttler <hv@…>

Attachment: settingtwice.diff added

comment:1 Changed 10 years ago by anonymous

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

comment:2 Changed 10 years ago by Thomas Güttler <hv@…>

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

comment:3 Changed 10 years ago by Marc Fargas <telenieko@…>

Triage Stage: UnreviewedAccepted

comment:4 Changed 10 years ago by Gary Wilson <gary.wilson@…>

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.

Changed 10 years ago by Gary Wilson <gary.wilson@…>

Attachment: 4385.diff added

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

comment:5 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Triage Stage: AcceptedReady for checkin

comment:6 Changed 10 years ago by Gary Wilson <gary.wilson@…>

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

comment:7 Changed 10 years ago by Malcolm Tredinnick

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