microsoft / yardl

Tooling for streaming instrument data
https://microsoft.github.io/yardl/
MIT License
29 stars 5 forks source link

Python ndjson error reading aliased nullable union with value None #114

Closed naegelejd closed 7 months ago

naegelejd commented 7 months ago

Using yardl v0.4.0, if you add an aliased nullable union to a Protocol sequence, the NDJSON reader will crash if the value of that step is None.

Example:

GenericNullableUnion2<T1, T2>: [null, T1, T2]

RecordWithUnions: !record
  fields:
    value: [null, int, string]
    aliasedValue: GenericNullableUnion2<int, string>

Then, using the following code to convert an instance of RecordWithUnions to json and back again:

import yay

converter = yay.ndjson.RecordWithUnionsConverter()

json = converter.to_json(yay.RecordWithUnions())

r = converter.from_json(json)

The last line throws:

Traceback (most recent call last):
  File "/workspaces/yardl/joe/issue-#113/python/test.py", line 7, in <module>
    r = converter.from_json(json)
        ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/yardl/joe/issue-#113/python/yay/ndjson.py", line 58, in from_json
    aliased_value=self._aliased_value_converter.from_json(json_object["aliasedValue"],),
                                                          ~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'aliasedValue'