diff --git a/AUTHORS b/AUTHORS index a8b7fecf87..a3848545e6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -330,6 +330,7 @@ answer newbie questions, and generally made Django that much better: Florian Demmer Florian Moussous Fran Hrženjak + Francesco Panico Francisco Albarran Cristobal Francisco Couzo François Freitag diff --git a/django/forms/forms.py b/django/forms/forms.py index 7c9f1034d2..6884e6e724 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -174,10 +174,6 @@ class BaseForm(RenderableFormMixin): 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: @@ -189,9 +185,9 @@ class BaseForm(RenderableFormMixin): ", ".join(sorted(self.fields)), ) ) - bound_field = field.get_bound_field(self, name) - self._bound_fields_cache[name] = bound_field - return bound_field + 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] @property def errors(self): diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 6005472194..930a200b14 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -4579,6 +4579,22 @@ Options: