-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Hi. thanks for the nice gem!
I'd like to report an issue.
Description
We have the following Avro schema:
{
"type": "record",
"namespace": "xyz",
"name": "failureExample",
"version": 1,
"fields": [
{
"name": "position",
"type": ["string", "null"],
"default": "1",
"logicalType": "standardDecimal"
}
]
}That results into the following error on attempt to build model from it:
RuntimeError: a null type in a union must be the first member
This exception comes from here: https://github.com/salsify/avromatic/blob/master/lib/avromatic/model/attributes.rb#L180
The problem is, that if we swap string and null types in the array, the the schema becomes invalid, because we need to use default value, and according to the avro specification default value type must match the first type in the union.
https://avro.apache.org/docs/1.8.2/spec.html#schema_record
default: A default value for this field, used when reading instances that lack this field (optional). Permitted values depend on the field's schema type, according to the table below. Default values for union fields correspond to the first schema in the union Default values for bytes and fixed fields are JSON strings, where Unicode code points 0-255 are mapped to unsigned 8-bit byte values 0-255.
Expected behaviour
The error should not be raised