dataclasses-jsonschema
dataclasses-jsonschema copied to clipboard
Improved behaviour when decoding nullable values that did not come from the encoder
If a type is nullable and we got None input, we should decode as None and not the _NULL_TYPE class.
Otherwise it causes strange behaviour
I think this would break the from_dict
. For example:
@dataclass
class PayloadWithNullable(InputModel):
required: str
opt_nullable: Nullable[Optional[str]] = None
# ...
assert PayloadWithNullable.from({'required': 'foo'}) == PayloadWithNullable(required='foo', opt_nullable=None)
assert PayloadWithNullable.from({'required': 'foo', 'opt_nullable': None}) == PayloadWithNullable(required='foo', opt_nullable=NULL)
Those asserts are both true @jsangilve ? The second one should also be
assert PayloadWithNullable.from({'required': 'foo', 'opt_nullable': None}) == PayloadWithNullable(required='foo', opt_nullable= None)