Hi,
Reading on the documentation regarding formsets' validation:
It seems that an overrided clean() method in a custom formset deriving from forms.BaseFormSet would be called when validating a formset (in particular, when explicitly calling Formset's is_valid() method).
Yet, it does not appear to be the case in this example:
class CustomForm(forms.Form):
title = forms.CharField()
class CustomFormset(forms.BaseFormSet):
def clean(self):
raise forms.ValidationError("This error is always raised, displaying it is success for the test.")
def formset_error(request):
FormSetClass = formset_factory(CustomForm, formset=CustomFormset, extra=2)
if request.method == 'POST':
formset = FormSetClass(request.POST)
if formset.is_valid():
pass
else:
formset = FormSetClass()
return render(request, "form.html", { 'formset': formset })
The ValidationError is not raised (as the clean() method is not invoked, as shown by a debugger).
Is this the expected behaviour ? Or should I report a bug ?
Thank you for reading,
Ad