I have the next enum:
class EStatus(enum.IntEnum):
NEW = 0
MODIFIED = 1
And schema:
ARGS = {
'status': EnumField(EStatus, by_value=True, required=False)
}
After in Flask I declared GET-method with webargs:
@use_args(ARGS, location='query')
def get(self, args: Dict[str, any]):
return []
And it fails with error:
{'messages': {'query': {'status': ['Invalid enum value 1']}}, 'schema': <GeneratedSchema(many=False)>, 'headers': None}
I've checked it in debugger and found that EnumField calls EStatus(value). The problem is that my value is str type because of it's from query parameters.
How to make to EnumField cast it to int before call EStatus(value)?
Hopefully for your problem you should be able to convert str to Enum type using from_str staticmethod.