Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3842

[Python] Cannot write a record in a union of [map, record]

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.12.0, 1.11.2
    • None
    • python
    • None
    • Python 3.10.3
      avro 1.11 and 1.12

    Description

      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:

      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)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            stestagg Steve Stagg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: