#27821 closed Cleanup/optimization (fixed)
Documentation of the return value of clean_<fieldname>() could be clarified
Reported by: | Christian Ullrich | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The documentation on form validation (/ref/forms/validation/) has this to say regarding the clean_<fieldname> method on a Form subclass:
This method should return the cleaned value obtained from cleaned_data, regardless of whether it changed anything or not.
This is incorrect; the method should return the value to be used for further processing, because its result is unconditionally put into cleaned_data:
(from django.forms.forms.Form._clean_fields():)
if hasattr(self, 'clean_%s' % name): value = getattr(self, 'clean_%s' % name)() self.cleaned_data[name] = value
Change History (5)
comment:1 by , 8 years ago
Has patch: | set |
---|---|
Summary: | Documentation on form validation is wrong → Documentation of the return value of clean_<fieldname>() could be clarified |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
comment:2 by , 8 years ago
"The return value of this method replaces the existing value in cleaned_data, so [...]", perhaps? Otherwise it looks good to me.
I see how the current wording could be interpreted incorrectly. What do you think of this proposal:
docs/ref/forms/validation.txt
the cleaned data, whether you have changed it ornot.