[Django] #30940: Documentation on formsets lists incomplete code to detect errors in clean()

5 views
Skip to first unread message

Django

unread,
Nov 1, 2019, 6:28:31 AM11/1/19
to django-...@googlegroups.com
#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.

Django

unread,
Nov 5, 2019, 2:34:49 AM11/5/19
to django-...@googlegroups.com
#30940: Documentation on formsets lists incomplete code to detect errors in clean()
-------------------------------+--------------------------------------
Reporter: Tiemo | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 2.2
Severity: Normal | Resolution: invalid

Keywords: documentation | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => invalid
* easy: 1 => 0


Comment:

Since f32d24652b920135eb6a0f3de74599f03e181731 forms that are to be
deleted **do not** have their errors appended to the formset's errors.

--
Ticket URL: <https://code.djangoproject.com/ticket/30940#comment:1>

Reply all
Reply to author
Forward
0 new messages