dataclasses-json icon indicating copy to clipboard operation
dataclasses-json copied to clipboard

fix: prevent unwrapping union type with none value

Open kennyworkman opened this issue 3 years ago • 0 comments

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.

kennyworkman avatar Jul 16 '21 19:07 kennyworkman