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

Optional fields with value None raises exception on load #11

Closed
sveinse opened this issue Jan 3, 2020 · 1 comment · Fixed by #12
Closed

Optional fields with value None raises exception on load #11

sveinse opened this issue Jan 3, 2020 · 1 comment · Fixed by #12

Comments

@sveinse
Copy link
Collaborator

sveinse commented Jan 3, 2020

Running on python 3.8.0 on Windows 10, 32-bit version in a venv. desert retrieved from master commit a9b41e1.

desert does not support reading input data containing None from a schema with Optional type. The following test shows the issue:

def test_optional_present(module):
    """Including optional with None set the field."""

    @module.dataclass
    class A:
        x: t.Optional[int]

    data = desert.schema_class(A)().load({"x": None})
    assert data == A(None)

This will fail with the error: marshmallow.exceptions.ValidationError: {'x': ['Field may not be null.']}. The documentation for typing.Optional states that it is equivalent of Union[X, None] indicates that None is valid input to a Optional field.

@python-desert
Copy link
Collaborator

Thanks for reporting. I can reproduce the issue. I'll try to get it fixed over the weekend.

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

Successfully merging a pull request may close this issue.

1 participant