dataclasses-json
dataclasses-json copied to clipboard
fix: prevent unwrapping union type with none value
Motivation
With a field like so, the library attempted to incorrectly decode the type even if there was a None value.
control_data: Optional[Dict[str, Dict[str, Any]]] = None,
Resulting in the trace when control_data=None
.
File ".../python3.8/site-packages/dataclasses_json/core.py", line 258, in _decode_generic
ks = _decode_dict_keys(k_type, value.keys(), infer_missing)
AttributeError: 'list' object has no attribute 'keys'
This small fix simply checks if the value of an Optional is None. If so, it returns it.