Parameters of EnumField are ignored when loading a schema
Grennith opened this issue · comments
If a field is declared as follows, the line referenced above drops the parameters default and by_value (and any other parameters specified).
some_field: SomeEnum = EnumField(enum=SomeEnum, default=SomeEnum.FOO, by_value=True)
One quick workaround would be to check for the type of default
as it already is an EnumField. There's no reason to instantiate one again dropping all parameters imho:
if isinstance(typ, EnumMeta):
import marshmallow_enum
return default if isinstance(default, marshmallow_enum.EnumField) \
else marshmallow_enum.EnumField(typ, **metadata)
I think this is a dup of #228 (or vice versa).
Note that:
@dataclass
class SomeData:
some_field: SomeEnum = EnumField(...)
is not correct.
Correct usage would be, e.g.:
@dataclass
class SomeData:
some_field: SomeEnum = dataclasses.field(default=SomeEnum.FOO, metadata={"by_value": True})
I don't think this is a bug, so I'm closing this. If conditions warrant, please comment on and reopen #228.