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

Improved behaviour when decoding nullable values that did not come from the encoder

Open amigold opened this issue 4 years ago • 2 comments

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

amigold avatar Sep 26 '20 18:09 amigold

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)

jsangilve avatar Oct 15 '20 08:10 jsangilve

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)

amigold avatar Oct 15 '20 09:10 amigold