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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Carsten Fuchs-4
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

--
You received this message because you are subscribed to the Google Groups "Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ca5755d2-f905-f9ed-a8a9-60704bdaac4d%40cafu.de.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Carlton Gibson-3
Hi Carsten. 

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

Thanks. 
C. 

On Wednesday, 8 May 2019 13:58:25 UTC+2, Carsten Fuchs wrote:
Dear group,

I just upgraded from Django 1.11 to 2+ and thereby found <a href="https://code.djangoproject.com/ticket/28321" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28321\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFIosUSpyTErgLbaWfXjQ5jVA1VTw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28321\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFIosUSpyTErgLbaWfXjQ5jVA1VTw&#39;;return true;">https://code.djangoproject.com/ticket/28321
The ticket was resolved with commit <a href="https://github.com/django/django/commit/f32d24652b920135eb6a0f3de74599f03e181731" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2Ff32d24652b920135eb6a0f3de74599f03e181731\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEdmlcdeNUNjy88pYjiq7O3gARgMA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2Ff32d24652b920135eb6a0f3de74599f03e181731\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEdmlcdeNUNjy88pYjiq7O3gARgMA&#39;;return true;">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

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/a4703c73-6c25-46ef-a948-c3377057d09a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.