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

Schema generated via AvroSchema is not compatible with itself

VotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.11.3
    • 1.12.0, 1.11.4
    • rust
    • None
    • Rust 1.79.0

    Description

      We encountered an issue where our Avro schema generated with the AvroSchema macro is not compatible with itself. That is, the can_read function fails to read the generated schema. Here's a minimal reproducible example:

      use apache_avro::AvroSchema;
      
      #[derive(AvroSchema)]
      struct Foo {
          a: Vec<Bar>,
          b: Vec<Bar>,
      }
      
      #[derive(AvroSchema)]
      struct Bar {
          value: i32,
      }
      
      #[cfg(test)]
      mod tests {
          use super::*;
      
          #[test]
          fn schema_reflexivity() {
              let schema = Foo::get_schema();
              println!("{}", &schema.canonical_form());
              assert_eq!(&schema, &schema);
              assert!(apache_avro::schema_compatibility::SchemaCompatibility::can_read(&schema, &schema)); // this fails
          }
      }
      

      This is with the only dependency in Cargo.toml being:

      apache-avro = { version = "0.16.0", features = ["derive"] }
      

      The automatically generated Avro schema is:

      {
          "name": "Foo",
          "type": "record",
          "fields": [
              {
                  "name": "a",
                  "type": {
                      "type": "array",
                      "items": {
                          "name": "Bar",
                          "type": "record",
                          "fields": [
                              {
                                  "name": "value",
                                  "type": "int"
                              }
                          ]
                      }
                  }
              },
              {
                  "name": "b",
                  "type": {
                      "type": "array",
                      "items": "Bar"
                  }
              }
          ]
      }
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            mgrigorov Martin Tzvetanov Grigorov
            marcolugo Marco Lugo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment