Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#21894 closed Bug (fixed)

Error in example code in django.forms.Form.clean()¶

Reported by: richard.kellner@… 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)

21894.diff (1.1 KB ) - added by Tim Graham 9 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Baptiste Mispelon, 10 years ago

Resolution: worksforme
Status: newclosed

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.

in reply to:  1 comment:2 by Carsten Fuchs, 9 years ago

Resolution: worksforme
Status: closednew

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 Tim Graham, 9 years ago

Attachment: 21894.diff added

comment:3 by Tim Graham, 9 years ago

Has patch: set
Triage Stage: UnreviewedAccepted

comment:4 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 80855a4:

Fixed #21894 -- Corrected a form.clean() example in case a superclass doesn't return data.

comment:5 by Tim Graham <timograham@…>, 9 years ago

In 6861c20:

[1.8.x] Fixed #21894 -- Corrected a form.clean() example in case a superclass doesn't return data.

Backport of 80855a4b3787bace050a8b4a2b80f79306e69812 from master

comment:6 by Tim Graham <timograham@…>, 9 years ago

In 55ed23fd:

[1.9.x] Fixed #21894 -- Corrected a form.clean() example in case a superclass doesn't return data.

Backport of 80855a4b3787bace050a8b4a2b80f79306e69812 from master

Note: See TracTickets for help on using tickets.
Back to Top