Merge branch 'extra-value-exc' of surabujin/colander into pr/241
Renamed UnknownItemsError to UnsupportedFields.
This commit is contained in:
@@ -4,6 +4,9 @@ unreleased
|
||||
Features
|
||||
--------
|
||||
|
||||
- Add new exception ExtraItemsError. Used to pass to the caller a list of extra
|
||||
field detected in cstruct.
|
||||
|
||||
- Add ``drop`` functionality to ``Sequence`` type.
|
||||
|
||||
Bug Fixes
|
||||
|
@@ -126,4 +126,5 @@ Contributors
|
||||
- Nando Florestan, 2014/11/27
|
||||
- Amos Latteier, 2014/11/30
|
||||
- Jimmy Thrasibule, 2014/12/11
|
||||
- Dmitry Bogun, 2015/09/10
|
||||
- Tinne Cahy, 2015/12/22
|
||||
|
@@ -205,6 +205,18 @@ class Invalid(Exception):
|
||||
result of an execution of this exception's ``asdict`` method"""
|
||||
return pprint.pformat(self.asdict())
|
||||
|
||||
|
||||
class UnsupportedFields(Invalid):
|
||||
"""
|
||||
Exception used when schema object detect unknown fields in the
|
||||
cstruct during deserialize.
|
||||
"""
|
||||
|
||||
def __init__(self, node, items, msg=None):
|
||||
super(UnsupportedFields, self).__init__(node, msg)
|
||||
self.items = items
|
||||
|
||||
|
||||
class All(object):
|
||||
""" Composite validator which succeeds if none of its
|
||||
subvalidators raises an :class:`colander.Invalid` exception"""
|
||||
@@ -667,11 +679,10 @@ class Mapping(SchemaType):
|
||||
|
||||
if self.unknown == 'raise':
|
||||
if value:
|
||||
raise Invalid(
|
||||
node,
|
||||
_('Unrecognized keys in mapping: "${val}"',
|
||||
mapping={'val':value})
|
||||
)
|
||||
raise UnsupportedFields(
|
||||
node, value,
|
||||
msg=_('Unrecognized keys in mapping: "${val}"',
|
||||
mapping={'val': value}))
|
||||
|
||||
elif self.unknown == 'preserve':
|
||||
result.update(value)
|
||||
|
@@ -718,10 +718,12 @@ class TestMapping(unittest.TestCase):
|
||||
self.assertEqual(result, {'a':1})
|
||||
|
||||
def test_deserialize_unknown_raise(self):
|
||||
import colander
|
||||
node = DummySchemaNode(None)
|
||||
node.children = [DummySchemaNode(None, name='a')]
|
||||
typ = self._makeOne(unknown='raise')
|
||||
e = invalid_exc(typ.deserialize, node, {'a':1, 'b':2})
|
||||
self.assertTrue(isinstance(e, colander.UnsupportedFields))
|
||||
self.assertEqual(e.msg.interpolate(),
|
||||
"Unrecognized keys in mapping: \"{'b': 2}\"")
|
||||
|
||||
|
@@ -48,6 +48,15 @@ Exceptions
|
||||
from a widget as the value which should be redisplayed when an
|
||||
error is shown.
|
||||
|
||||
.. autoclass:: UnsupportedFields
|
||||
|
||||
.. attribute:: fields
|
||||
|
||||
The ``dict`` with all detected extra fields and their values.
|
||||
|
||||
Nodes that contain extra fields can be located by the position of
|
||||
this exception in the exception tree hierarchy.
|
||||
|
||||
.. autoclass:: UnboundDeferredError
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user