Fixed #32901 -- Optimized BaseForm.__getitem__().

This commit is contained in:
Chris Jerdonek 2021-07-05 06:21:23 -07:00 committed by GitHub
parent 2231429991
commit edde2a0699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -149,6 +149,10 @@ class BaseForm:
def __getitem__(self, name):
"""Return a BoundField with the given name."""
try:
return self._bound_fields_cache[name]
except KeyError:
pass
try:
field = self.fields[name]
except KeyError:
@ -159,9 +163,9 @@ class BaseForm:
', '.join(sorted(self.fields)),
)
)
if name not in self._bound_fields_cache:
self._bound_fields_cache[name] = field.get_bound_field(self, name)
return self._bound_fields_cache[name]
bound_field = field.get_bound_field(self, name)
self._bound_fields_cache[name] = bound_field
return bound_field
@property
def errors(self):