diff --git a/CHANGES.txt b/CHANGES.txt index 59fd55c..dfcc887 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,9 @@ Next release https://github.com/Pylons/colander/pull/12 , and https://github.com/Pylons/colander/issues/2 . +- Invalid.messages() now returns an empty list if there are no messages. + See https://github.com/Pylons/colander/pull/21 . + 0.9.6 (2012-02-14) ------------------ diff --git a/colander/__init__.py b/colander/__init__.py index 8764c29..d4f81a6 100644 --- a/colander/__init__.py +++ b/colander/__init__.py @@ -71,13 +71,15 @@ class Invalid(Exception): self.children = [] def messages(self): - """ Return an iterable of error messages for this exception - using the ``msg`` attribute of this error node. If the - ``msg`` attribute is iterable, it is returned. If it is not - iterable, a single-element list containing the ``msg`` value - is returned.""" + """ Return an iterable of error messages for this exception using the + ``msg`` attribute of this error node. If the ``msg`` attribute is + iterable, it is returned. If it is not iterable, and is + non-``None``, a single-element list containing the ``msg`` value is + returned. If the value is ``None``, an empty list is returned.""" if is_nonstr_iter(self.msg): return self.msg + if self.msg is None: + return [] return [self.msg] def add(self, exc, pos=None): diff --git a/colander/tests/test_colander.py b/colander/tests/test_colander.py index 792d321..9317caa 100644 --- a/colander/tests/test_colander.py +++ b/colander/tests/test_colander.py @@ -183,6 +183,11 @@ class TestInvalid(unittest.TestCase): exc = self._makeOne(node, 'msg') self.assertEqual(exc.messages(), ['msg']) + def test_messages_msg_None(self): + node = DummySchemaNode(None) + exc = self._makeOne(node, None) + self.assertEqual(exc.messages(), []) + class TestAll(unittest.TestCase): def _makeOne(self, validators): from colander import All