Inconsistency of clean method

18 views
Skip to first unread message

Matthew Pava

unread,
Jun 2, 2017, 3:21:28 PM6/2/17
to django...@googlegroups.com

I have been working with Django for several years and just discovered this gem in the documentation (emphasis mine):

 

https://docs.djangoproject.com/en/1.11/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other

If your form inherits another that doesn’t return a cleaned_data dictionary in its clean() method (doing so is optional), then don’t assign cleaned_data to the result of the super() call and use self.cleaned_data instead:”

 

I had always assumed that the clean method was required return the cleaned_data because I thought I had read that elsewhere.  Upon further investigation, I discovered that this requirement was changed in Django 1.7.  Any idea why?  (I obviously missed reading about that change.)  It does seem somewhat inconsistent since the clean_field methods all require the cleaned_data of the field to be returned.

 

I’ve been working on a formset and was used to the behavior of the super clean method always returning the cleaned_data dictionary.  …but, it doesn’t, and I’ve spent a great deal of time troubleshooting this issue believing otherwise.  I was wondering if we could/should ask the Django developers to return the cleaned_data in the formset classes since they do return cleaned_data in the form classes.

Tim Graham

unread,
Jun 3, 2017, 11:05:24 AM6/3/17
to Django users, Matthe...@iss.com
Here's the commit:

I can't find any related discussions but I think the reason is because the return was unnecessarily boilerplate in a lot of cases.

I'm not sure what behavior change for formsets you're proposing. Which method in Django would change?
Reply all
Reply to author
Forward
0 new messages