Friday, June 2, 2017

Inconsistency of clean method

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.

No comments:

Post a Comment