Skip to content
Browse files

Fix Sequence to re-raise exceptions with correctly mapped names.

When the Invalid exception from a child attribute was sucked into the
sequence's error_dict the key name was being incorrectly generated for
errors from immediate child attributes, i.e. those errors that have a
key of ''.

This is basically the same change that had already been applied in
Structure.validate().
  • Loading branch information...
1 parent 1ee682f commit 07ac4de3da78fa1ff90682657af0c2d7ef323ffc Matt Goodall committed Jan 14, 2009
Showing with 18 additions and 2 deletions.
  1. +5 −2 schemaish/attr.py
  2. +13 −0 schemaish/tests/test_attr.py
View
7 schemaish/attr.py
@@ -165,7 +165,10 @@ def validate(self, value):
self.attr.validate(item)
except Invalid, e:
for k, v in e.error_dict.items():
- error_dict['%s.%s' % (str(n), k)] = v
+ if k == '':
+ error_dict[str(n)] = v
+ else:
+ error_dict['%s.%s' % (str(n), k)] = v
try:
super(Sequence, self).validate(value)
@@ -304,7 +307,7 @@ def validate(self, value):
try:
super(Structure, self).validate(value)
except Invalid, e:
- error_dict.update(e.errror_dict)
+ error_dict.update(e.error_dict)
if error_dict:
raise Invalid(error_dict)
View
13 schemaish/tests/test_attr.py
@@ -97,6 +97,19 @@ class DateSequence(Sequence):
assert isinstance(StringSequence().attr, String)
assert isinstance(DateSequence().attr, Date)
+ def test_item_error(self):
+ """
+ Check sequence re-raise exceptions with correct names.
+ """
+ def fail(value):
+ raise validatish.Invalid('fail')
+ s = Sequence(String(validator=fail))
+ try:
+ s.validate([''])
+ self.fail()
+ except Invalid, e:
+ self.assertTrue('0' in e.error_dict)
+
class TestTuple(unittest.TestCase):

0 comments on commit 07ac4de

Please sign in to comment.
Something went wrong with that request. Please try again.