#27821: Documentation of the return value of clean_<fieldname>() could be 
clarified
--------------------------------------+------------------------------------
     Reporter:  Christian Ullrich     |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Documentation         |                  Version:  1.10
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  1                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

 * has_patch:  0 => 1
 * type:  Bug => Cleanup/optimization
 * stage:  Unreviewed => Accepted


Comment:

 I see how the current wording could be interpreted incorrectly. What do
 you think of this proposal:
 {{{ #!diff
 diff --git a/docs/ref/forms/validation.txt b/docs/ref/forms/validation.txt
 index 6d3edf9..622fb68 100644
 --- a/docs/ref/forms/validation.txt
 +++ b/docs/ref/forms/validation.txt
 @@ -69,8 +69,9 @@ overridden:
    formfield-specific piece of validation and, possibly,
    cleaning/normalizing the data.

 -  This method should return the cleaned value obtained from
 ``cleaned_data``,
 -  regardless of whether it changed anything or not.
 +  The return value of this method is inserted into the form's
 ``cleaned_data``,
 +  so it must be the field's value from ``cleaned_data`` (even if you
 didn't
 +  change it) or a new cleaned value.

  * The form subclass's ``clean()`` method can perform validation that
 requires
    access to multiple form fields. This is where you might put in checks
 such as
 @@ -315,8 +316,8 @@ write a cleaning method that operates on the
 ``recipients`` field, like so::
              if "[email protected]" not in data:
                  raise forms.ValidationError("You have forgotten about
 Fred!")

 -            # Always return the cleaned data, whether you have changed it
 or
 -            # not.
 +            # Always return a value to use as the new cleaned data, even
 if
 +            # this method didn't change it.
              return data

  .. _validating-fields-with-clean:
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27821#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.baf077cffd9e596cbc2751c535a7ac1d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to