#30940: Documentation on formsets lists incomplete code to detect errors in clean() -----------------------------------------+------------------------------- Reporter: blubber | Owner: nobody Type: Bug | Status: new Component: Documentation | Version: 2.2 Severity: Normal | Keywords: documentation Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 1 UI/UX: 0 | -----------------------------------------+------------------------------- The documentation on FormSets at https://docs.djangoproject.com/en/2.2/topics/forms/formsets/ lists incomplete sample code to determine whether the formset has erorrs in clean().
The listing: {{{ >>> class BaseArticleFormSet(BaseFormSet): ... def clean(self): ... """Checks that no two articles have the same title.""" ... if any(self.errors): ... # Don't bother validating the formset unless each form is valid on its own ... return }}} This check is not complete, the full_clean method calls form.errors on all forms in the formset at r349, even on forms that are to be removed. This results in self.errors containing errors for forms that are to be deleted. However, FormSet.is_valid ignores errors in forms that are to be removed. The result is that the any(self.errors) snippet returns True, even if only removed forms contain errors. -- Ticket URL: <https://code.djangoproject.com/ticket/30940> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.3f574f5e838b780e50d9749632801e1a%40djangoproject.com.