Skip to content

Allow None value for strings #274

@jenstroeger

Description

@jenstroeger

My question seems somewhat similar to other None related problems, e.g. #140, #186, #204.

It seems to me that deserializing a None string should yield the same, instead of colander.Invalid: {'name': 'Required'} which is misleading because name does indeed exist:

>>> class Person(colander.MappingSchema):
...     name = colander.SchemaNode(colander.String(allow_empty=True))
>>> Person().deserialize({'name': 'foo'})
{'name': 'foo'}
>>> Person().deserialize({'name': ''})
{'name': ''}
>>> Person().deserialize({'name': None})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/.../python3.4/site-packages/colander/__init__.py", line 2058, in deserialize
    appstruct = self.typ.deserialize(self, cstruct)
  File "/.../python3.4/site-packages/colander/__init__.py", line 719, in deserialize
    return self._impl(node, cstruct, callback)
  File "/.../python3.4/site-packages/colander/__init__.py", line 699, in _impl
    raise error
colander.Invalid: {'name': 'Required'}

A proposed solution can be found on Stackoverflow but it seems more like a workaround for this issue than a proper solution.

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