dataclass-wizard icon indicating copy to clipboard operation
dataclass-wizard copied to clipboard

Throw error when dict contains fields not found in the dataclass

Open fakuivan opened this issue 2 years ago • 2 comments

Is it possible to throw an error whenever fields not declared in the dataclass are present in the input being parsed? Right now it seems like extra fields are just ignored.

fakuivan avatar Mar 08 '23 14:03 fakuivan

I've found that the metaclass config raise_on_unknown_json_key does exactly what I need. I've found it in the following test case:

https://github.com/rnag/dataclass-wizard/blob/d59bd79dd94effe90b00e667c6ed7539c7e98b43/tests/unit/test_dump.py#L36

Any ideas of why it's not documented or why it specifically mentions JSON?

fakuivan avatar Mar 08 '23 16:03 fakuivan

It is documented here: https://dataclass-wizard.readthedocs.io/en/latest/common_use_cases/meta.html and is intended for use with the from_dict helper function according to those docs.

lmmx avatar Mar 19 '23 14:03 lmmx