Code

Opened 7 years ago

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

Download all attachments as: .zip

Change History (9)

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

comment:1 Changed 7 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 7 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 7 years ago by Marc Fargas <telenieko@…>

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 7 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 7 years ago by Gary Wilson <gary.wilson@…>

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

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

  • Triage Stage changed from Accepted to Ready for checkin

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

  • Summary changed from Typo: value gets set twice to cleaned_data gets set twice even when no clean_<field> method

comment:7 Changed 7 years ago by mtredinnick

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

(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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.