desert
desert copied to clipboard
module.field(metadata={"default": default}) doesn't work
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.']}
I don't think that usage ought to be supported. There are several options already available for setting defaults.