Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow None value for strings #274

Open
jenstroeger opened this issue Oct 18, 2016 · 0 comments
Open

Allow None value for strings #274

jenstroeger opened this issue Oct 18, 2016 · 0 comments

Comments

@jenstroeger
Copy link
Contributor

jenstroeger commented Oct 18, 2016

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.

@jenstroeger jenstroeger changed the title Allow None value for strings Allow None value for strings Oct 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant