Loading django/forms/forms.py +6 −1 Original line number Diff line number Diff line Loading @@ -140,7 +140,12 @@ class BaseForm(object): field = self.fields[name] except KeyError: raise KeyError( "Key %r not found in '%s'" % (name, self.__class__.__name__)) "Key '%s' not found in '%s'. Choices are: %s." % ( name, self.__class__.__name__, ', '.join(sorted(f for f in 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] Loading tests/forms_tests/tests/test_forms.py +2 −3 Original line number Diff line number Diff line Loading @@ -71,10 +71,9 @@ class FormsTestCase(SimpleTestCase): '<input type="text" name="birthday" value="1940-10-9" id="id_birthday" />' ) nonexistenterror = "Key u?'nonexistentfield' not found in 'Person'" with six.assertRaisesRegex(self, KeyError, nonexistenterror): msg = "Key 'nonexistentfield' not found in 'Person'. Choices are: birthday, first_name, last_name." with self.assertRaisesMessage(KeyError, msg): p['nonexistentfield'] self.fail('Attempts to access non-existent fields should fail.') form_output = [] Loading Loading
django/forms/forms.py +6 −1 Original line number Diff line number Diff line Loading @@ -140,7 +140,12 @@ class BaseForm(object): field = self.fields[name] except KeyError: raise KeyError( "Key %r not found in '%s'" % (name, self.__class__.__name__)) "Key '%s' not found in '%s'. Choices are: %s." % ( name, self.__class__.__name__, ', '.join(sorted(f for f in 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] Loading
tests/forms_tests/tests/test_forms.py +2 −3 Original line number Diff line number Diff line Loading @@ -71,10 +71,9 @@ class FormsTestCase(SimpleTestCase): '<input type="text" name="birthday" value="1940-10-9" id="id_birthday" />' ) nonexistenterror = "Key u?'nonexistentfield' not found in 'Person'" with six.assertRaisesRegex(self, KeyError, nonexistenterror): msg = "Key 'nonexistentfield' not found in 'Person'. Choices are: birthday, first_name, last_name." with self.assertRaisesMessage(KeyError, msg): p['nonexistentfield'] self.fail('Attempts to access non-existent fields should fail.') form_output = [] Loading