desert icon indicating copy to clipboard operation
desert copied to clipboard

module.field(metadata={"default": default}) doesn't work

Open altendky opened this issue 5 years ago • 1 comments

I haven't thought through whether this even ought to be a feature but there's code related to it and it doesn't seem to work. The following fails.

def test_default_via_metadata_loads(module):
    """"""

    default = 5

    @module.dataclass
    class A:
        x: int = module.field(metadata={"default": default})

    schema = desert.schema_class(A)()

    assert schema.load({}) == A()
tests/test_make.py:313 (test_default_via_metadata_loads[attrs])
tests/test_make.py:325: in test_default_via_metadata_loads
    assert schema.load({}) == A()
venv/lib/python3.8/site-packages/marshmallow/schema.py:713: in load
    return self._do_load(
venv/lib/python3.8/site-packages/marshmallow/schema.py:892: in _do_load
    raise exc
E   marshmallow.exceptions.ValidationError: {'x': ['Missing data for required field.']}

altendky avatar Jan 29 '20 05:01 altendky

I don't think that usage ought to be supported. There are several options already available for setting defaults.

python-desert avatar Jan 29 '20 05:01 python-desert