Skip to content

improper Invalid.asdict behavior when raising an exception for a subnode #182

Open
@mmerickel

Description

@mmerickel
def MyMappingValidator(node, value):
    raise colander.Invalid(node['foo'], 'value must be less than 50')

schema = colander.SchemaNode(
    colander.Sequence(),
    colander.SchemaNode(
        colander.Mapping(),
        colander.SchemaNode(colander.Integer(), name='foo'),
        validator=MyMappingValidator,
    ),
)

schema.deserialize([{'foo': 100}])

Results in the following traceback:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/michael/work/scratch/eggs/colander-1.0b1-py2.7.egg/colander/__init__.py", line 1917, in deserialize
    appstruct = self.typ.deserialize(self, cstruct)
  File "/Users/michael/scratch/eggs/colander-1.0b1-py2.7.egg/colander/__init__.py", line 988, in deserialize
    return self._impl(node, cstruct, callback, accept_scalar)
  File "/Users/michael/scratch/eggs/colander-1.0b1-py2.7.egg/colander/__init__.py", line 930, in _impl
    raise error
Invalid: {'0': 'value must be less than 50'}

Whereas if I put the validator on the node itself, the error message path properly indicates {'0.foo': 'value must be less than 50'}. Please ignore the simplicity of the example, the actual use case is for a validator that checks the subnodes based on other subnodes and the error messages do not come out correct right now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions