Skip to content

'coerce' still ignores 'nullable': True #427

@andreymal

Description

@andreymal

#269 was fixed, but only for integer:

>>> v = cerberus.Validator({'foo': {'coerce': int, 'nullable': True, 'type': 'integer'}})
>>> v.normalized({'foo': None})
{'foo': None}

Just replace integer to string:

>>> v = cerberus.Validator({'foo': {'coerce': str, 'nullable': True, 'type': 'string'}})
>>> v.normalized({'foo': None})

Expected behavior: {'foo': None}

Actual behavior: {'foo': 'None'}

So I still have to use a workaround 'coerce': lambda x: str(x) if x is not None else None

But now I'm not sure if it's a bug or a feature (duplicate of #142?). If this is a feature, please describe this behavior in the documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions