Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#3896 closed (fixed)

pass value to field specific clean function

Reported by: Henrik Vendelbo <info@…> Owned by: nobody
Component: Forms Version: master
Severity: Keywords:
Cc: tailofthesun@…, hv@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by ubernostrum)

newforms has this bit of code in the full_clean function:

            try:
                value = field.clean(value)
                self.clean_data[name] = value
                if hasattr(self, 'clean_%s' % name):
                    value = getattr(self, 'clean_%s' % name)()
                self.clean_data[name] = value
            except ValidationError, e:
                errors[name] = e.messages

Why is value not passed to the clean_%s function? Since it is required to return the accepted value, it is odd that it is forced to look it up. Basicly a dictionary read and assignment is required with no obvious gain. Logically I find it odd as well that clean_data contains values that are not cleaned fully yet.

Attachments (2)

3896.diff (690 bytes) - added by Gary Wilson <gary.wilson@…> 8 years ago.
Pass the value to clean_XXX method and don't save to clean_data first.
3896.2.diff (2.0 KB) - added by Gary Wilson <gary.wilson@…> 8 years ago.
Only the passing of value to clean_XXX method, with test fixes.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 8 years ago by ubernostrum

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

(cleaning up code formatting in description)

comment:2 Changed 8 years ago by Gary Wilson <gary.wilson@…>

  • Triage Stage changed from Unreviewed to Design decision needed

Seems logical to me. I think it is certainly a bug that clean_data will retain the value even if clean_XXX raises a ValidationError. So even if it is decided that value shouldn't be passed to clean_XXX, we at least need to fix the clean_data problem.

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

Pass the value to clean_XXX method and don't save to clean_data first.

comment:3 Changed 8 years ago by Gary Wilson <gary.wilson@…>

  • Has patch set
  • Needs documentation set
  • Needs tests set

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

Only the passing of value to clean_XXX method, with test fixes.

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

If this change goes in, then also consider removing the line specified in the first patch, which would fix #4391.

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

  • Needs tests unset

comment:6 Changed 8 years ago by anonymous

  • Cc tailofthesun@… added

comment:7 Changed 8 years ago by PhiR

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

it's really an implementation detail, but none the less fixed in [5346].

comment:8 Changed 7 years ago by guettli

  • Cc hv@… added
Note: See TracTickets for help on using tickets.
Back to Top