You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Steve Stagg (Jira)" <ji...@apache.org> on 2023/08/24 10:39:00 UTC
[jira] [Created] (AVRO-3842) [Python] Cannot write a record in a union of [map, record]
Steve Stagg created AVRO-3842:
---------------------------------
Summary: [Python] Cannot write a record in a union of [map, record]
Key: AVRO-3842
URL: https://issues.apache.org/jira/browse/AVRO-3842
Project: Apache Avro
Issue Type: Bug
Components: python
Affects Versions: 1.11.2, 1.12.0
Environment: Python 3.10.3
avro 1.11 and 1.12
Reporter: Steve Stagg
The following script raises a validation exception because the map schema .validate doesn't check the value types, so union schema picks the wrong path, and then raises:
{code:python}
from io import BytesIO
import json
import avro.io
import avro.schema
SCHEMA = [
{"type": "map", "values": "int"},
{
"type": "record",
"name": "A",
"fields": [
{"aliases": [], "type": "string", "name": "x"},
],
},
]
datum = {'x': 'Hello'}
if __name__ == '__main__':
sch = avro.schema.parse(json.dumps(SCHEMA))
buf = BytesIO()
encoder = avro.io.BinaryEncoder(buf)
writer = avro.io.DatumWriter(sch)
encoded = writer.write(datum, encoder)
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)