Opened 3 years ago

Closed 14 months ago

Last modified 14 months ago

#21894 closed Bug (fixed)

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

Reported by: richard.kellner@… Owned by: nobody
Component: Documentation Version: master
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 14 months ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 3 years ago by Baptiste Mispelon

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.

comment:2 in reply to:  1 Changed 14 months ago by Carsten Fuchs

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.

Changed 14 months ago by Tim Graham

Attachment: 21894.diff added

comment:3 Changed 14 months ago by Tim Graham

Has patch: set
Triage Stage: UnreviewedAccepted

comment:4 Changed 14 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 80855a4:

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

comment:5 Changed 14 months ago by Tim Graham <timograham@…>

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 Changed 14 months ago by Tim Graham <timograham@…>

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