[1.7.x] Fixed #22570 -- Made Form.__getitem__ KeyError more descriptive.
Backport of df60db0e78
from master
This commit is contained in:
parent
2dd52d0433
commit
549b658241
|
@ -142,7 +142,8 @@ class BaseForm(object):
|
||||||
try:
|
try:
|
||||||
field = self.fields[name]
|
field = self.fields[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise KeyError('Key %r not found in Form' % name)
|
raise KeyError(
|
||||||
|
"Key %r not found in '%s'" % (name, self.__class__.__name__))
|
||||||
return BoundField(self, field, name)
|
return BoundField(self, field, name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -57,11 +57,11 @@ class FormsTestCase(TestCase):
|
||||||
self.assertHTMLEqual(str(p['first_name']), '<input type="text" name="first_name" value="John" id="id_first_name" />')
|
self.assertHTMLEqual(str(p['first_name']), '<input type="text" name="first_name" value="John" id="id_first_name" />')
|
||||||
self.assertHTMLEqual(str(p['last_name']), '<input type="text" name="last_name" value="Lennon" id="id_last_name" />')
|
self.assertHTMLEqual(str(p['last_name']), '<input type="text" name="last_name" value="Lennon" id="id_last_name" />')
|
||||||
self.assertHTMLEqual(str(p['birthday']), '<input type="text" name="birthday" value="1940-10-9" id="id_birthday" />')
|
self.assertHTMLEqual(str(p['birthday']), '<input type="text" name="birthday" value="1940-10-9" id="id_birthday" />')
|
||||||
try:
|
|
||||||
|
nonexistenterror = "Key u?'nonexistentfield' not found in 'Person'"
|
||||||
|
with self.assertRaisesRegexp(KeyError, nonexistenterror):
|
||||||
p['nonexistentfield']
|
p['nonexistentfield']
|
||||||
self.fail('Attempts to access non-existent fields should fail.')
|
self.fail('Attempts to access non-existent fields should fail.')
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
form_output = []
|
form_output = []
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue