﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35723	Change django.forms.formsets.all_valid() to use generator instead of list comprehension	Prashant Rana		"in function `all_valid` in `formsets.py` https://github.com/django/django/blob/main/django/forms/formsets.py#L576
we are using list comprehension to check if each individual formset is valid or not and then adding that to list and then computing all. in this approach, we have to go through all the formsets even if one of them is not valid and then check if all of them are true.

with this approach, we have to check all formsets first and then check if all of list is  valid ie True. An extra computation is happening even after if encounter not valid and in memory is also used .

my purposal is to use generator comprehension here instead of list comprehension.
benefits include, no need to validate all formset if one of formset is invalid and less in memory usages. 

so code should look like 

from 
{{{
def all_valid(formsets):
    """"""Validate every formset and return True if all are valid.""""""
    # List comprehension ensures is_valid() is called for all formsets.
    return all([formset.is_valid() for formset in formsets])
}}}
to 


{{{
def all_valid(formsets):
    """"""Validate every formset and return True if all are valid.""""""
    return all(formset.is_valid() for formset in formsets)
}}}


"	Cleanup/optimization	closed	Forms	dev	Normal	invalid	formsets, validation	Prashant Rana	Unreviewed	0	0	0	0	1	0
