#21894 closed Bug (fixed)
Error in example code in django.forms.Form.clean()¶
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | dev |
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
In Documentation version: development explanation of Cleaning and validating fields (https://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other) that depend on each other there is and error. Code in the sample would thow an exeptoion: TypeError: argument of type 'NoneType' is not iterable because function does not return anything back. Documentation in 1.6 is correct and does not have this error. To resolve add return statement at the end of both function in example:
# Always return the full collection of cleaned data. return cleaned_data
Attachments (1)
Change History (7)
follow-up: 2 comment:1 by , 11 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:2 by , 9 years ago
Resolution: | worksforme |
---|---|
Status: | closed → new |
Replying to bmispelon:
Hi,
The documentation is correct: this is a new feature in the development version of Django (soon-to-be 1.7), as described by the note under the example:
In previous versions of Django, form.clean() was required to return a dictionary of cleaned_data. This method may still return a dictionary of data to be used, but it’s no longer required.
This however (referring to this example code), is inconsistent with the example code's statement
cleaned_data = super(ContactForm, self).clean()
about which a subsequent paragraph says:
Note that the call to
super(ContactForm, self).clean()
in the example code ensures that any validation logic in parent classes is maintained.
That is, if the clean()
method of the parent class is coded like the example code for the child, the example code won't work.
by , 9 years ago
Attachment: | 21894.diff added |
---|
comment:3 by , 9 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Hi,
The documentation is correct: this is a new feature in the development version of Django (soon-to-be 1.7), as described by the note under the example: