After #28321 len(formset.forms) != len(formset.errors) is possible

43 views
Skip to first unread message

Carsten Fuchs

unread,
May 8, 2019, 7:58:25 AM5/8/19
to Django developers (Contributions to Django itself)
Dear group,

I just upgraded from Django 1.11 to 2+ and thereby found https://code.djangoproject.com/ticket/28321
The ticket was resolved with commit https://github.com/django/django/commit/f32d24652b920135eb6a0f3de74599f03e181731

Well, this change leaves us with a situation where `formset.forms` possibly no longer aligns with `self.errors`.

Was that intended?

The original ticket reporter suggested that for a deleted form with errors, an empty dict should be added to formset._errors in a formset's full_clean(). This would have preserved the alignment of formset.forms and formset.errors.

Note that the formset implementation often uses index-based iterations over the forms which seems to suggest, although there is no other indication or hint, that formset.forms[i] correlates to formset.errors[i] for all valid i. (That was also my understanding from the documentation before having looked at the implementation.)

[ In my application code I have the requirement that even deleted forms must meet certain validation criteria. Therefore I relied on the Django 1.11 / pre-#28321 behavior, where at the same time formset.is_valid() == True and any(formset.errors) == True was possible. While I found this undocumented, it was my preferred behavior. ]

Any thoughts?

Best regards,
Carsten

Carlton Gibson

unread,
May 8, 2019, 8:11:01 AM5/8/19
to Django developers (Contributions to Django itself)
Hi Carsten. 

Any chance you can put this into a failing test case in a PR? (Much easier to reason about code. 🙂) 

Thanks. 
C. 
Reply all
Reply to author
Forward
0 new messages