Browse files

Correctly supress top-level validator messages.

 - It's threebean's fault this wasn't correct the first time.
  • Loading branch information...
ralphbean committed Mar 29, 2012
1 parent c144b01 commit 8b15822e1ad6c29ff6f1d4ca31c4bd1db3da2aae
Showing with 8 additions and 7 deletions.
  1. +1 −3 tests/
  2. +7 −4 tw2/core/
@@ -147,11 +147,9 @@ class MatchyWidget(twc.CompoundWidget):
MatchyWidget.validate({'one': 'foo', 'two': 'bar'})
assert False, "Widget should not have validated."
except ValidationError as ve:
print ve.widget.error_msg
for child in ve.widget.children:
print child.error_msg
assert 'do not match' in ve.widget.children[0].error_msg
assert 'do not match' not in ve.widget.error_msg
assert 'childerror' not in ve.widget.error_msg
def test_auto_unflatten(self):
test = twc.CompoundWidget(id='a', children=[
@@ -631,12 +631,14 @@ def _validate(self, value, state=None):
# Validate self, usually a CompoundValidator or a FormEncode form-level
# validator.
any_child_errors = False
exception_validator = self.validator
if self.validator:
data = self.validator.to_python(data)
self.validator.validate_python(data, state)
except catch, e:
# If it failed to validate, check if the error_dict has any
# messages pertaining specifically to this widget's children.
error_dict = getattr(e, 'error_dict', {})
if not error_dict:
@@ -645,16 +647,17 @@ def _validate(self, value, state=None):
if getattr(c, 'key', None) in error_dict:
c.error_msg = error_dict[c.key]
data[c.key] = vd.Invalid
any_child_errors = True
exception_validator = None
any_errors = True
# Only re-raise this top-level exception if the validation error
# doesn't pertain to any of our children.
if not any_child_errors:
if exception_validator:
if any_errors:
raise vd.ValidationError('childerror', self.validator)
raise vd.ValidationError('childerror', exception_validator)
return data

0 comments on commit 8b15822

Please sign in to comment.