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

[Rust] Schema resolution fails when extending a nested record with a union type

    XMLWordPrintableJSON

Details

    Description

      Consider the following schema:

      {
          "type": "record",
          "name": "MyOuterRecord",
          "fields": [
              {
                  "name": "inner_record",
                  "type": [
                      "null",
                      {
                          "type": "record",
                          "name": "MyRecord",
                          "fields": [
                              {"name": "a", "type": "string"}
                          ]
                      }
                  ],
                  "default": null
              }
          ]
      }
      

      Over time one might decide to add a new optional enum field 'b' to `MyRecord`, resulting in the following schema:

      {
          "type": "record",
          "name": "MyOuterRecord",
          "fields": [
              {
                  "name": "inner_record",
                  "type": [
                      "null",
                      {
                          "type": "record",
                          "name": "MyRecord",
                          "fields": [
                              {"name": "a", "type": "string"},
                              {
                                  "name": "b",
                                  "type": [
                                      "null",
                                      {
                                          "type": "enum",
                                          "name": "MyEnum",
                                          "symbols": ["A", "B", "C"],
                                          "default": "C"
                                      }
                                  ],
                                  "default": null
                              }
                          ]
                      }
                  ]
              }
          ],
          "default": null
      }
      

      When one then serializes a message with the updated schema, and then attempts to deserialize it using the updated schema, while attempting to resolve it with the earlier schema, then schema resolution in Value::resolve_union() fails with `Error::FindUnionVariant`. This appears to be caused by `UnionSchema.find_schema_with_known_schemata()` failing to resolve the schema appropriately.

      I would not expect schema resolution to fail in this case. I will accompany this ticket with a test-case that allows reproduction.

      Attachments

        Issue Links

          Activity

            People

              mgrigorov Martin Tzvetanov Grigorov
              rheijdens Rik Heijdens
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 3h 20m
                  3h 20m