You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "vkopio (via GitHub)" <gi...@apache.org> on 2025/09/17 14:51:34 UTC

[I] Invalid canonical form parsing in some situations when array items has an inlined record type [avro-rs]

vkopio opened a new issue, #292:
URL: https://github.com/apache/avro-rs/issues/292

   I noticed that with version `0.20.0` when a schema has an array with an inlined record in the `items` field, the canonical form parsing will produce an invalid schema in certain situations.
   
   This can be reproduced with the following function. Here the inlining is done with two nested arrays:
   
   ```rust
   fn avro_bug() {
       let raw_schema = r#"{
               "type": "array",
               "items": {
                   "name": "foo",
                   "type": "record",
                   "fields": [
                       {
                           "name": "bar",
                           "type": "array",
                           "items": {
                               "type": "record",
                               "name": "baz",
                               "fields": [
                                   {
                                       "name": "quux",
                                       "type": "int"
                                   }
                               ]
                           }
                       }
                   ]
               }
           }"#;
   
       let schema = apache_avro::Schema::parse_str(&raw_schema).unwrap();
   
       println!("{}", &schema.canonical_form());
   
       let schema2 = apache_avro::Schema::parse_str(&schema.canonical_form()).unwrap(); // Panics here
   
       println!("{}", &schema2.canonical_form());
   }
   ```
   
   The output is the following:
   ```
   {"type":"array","items":{"name":"foo","type":"record","fields":[{"name":"bar","type":{"type":"array","items":"baz"},"items":{"name":"baz","type":"record","fields":[{"name":"quux","type":"int"}]}}]}}
   
   thread 'main' panicked at src/main.rs:30:76:
   called `Result::unwrap()` on an `Err` value: Error { details: Unknown primitive type: baz }
   ```
   
   Expanding the output from the first canonical form:
   
   ```json
   {
     "type": "array",
     "items": {
       "name": "foo",
       "type": "record",
       "fields": [
         {
           "name": "bar",
           "type": {
             "type": "array",
             "items": "baz"
           },
           "items": {
             "name": "baz",
             "type": "record",
             "fields": [
               {
                 "name": "quux",
                 "type": "int"
               }
             ]
           }
         }
       ]
     }
   }
   ```
   
   So the type of `bar` changes from `"array"` to `{"type": "array", "items": "baz"}`, but the outer array is canonized correctly.
   
   However, if we wrap the outer array into a record, this type change happens with the outer array but the inner array is canonized correctly. Here is a schema that can be used to reproduce this:
   ```json
   {
     "name": "wrapper",
     "type": "record",
     "fields": [
       {
         "name": "wrapped",
         "type": "array",
         "items": {
           "name": "foo",
           "type": "record",
           "fields": [
             {
               "name": "bar",
               "type": "array",
               "items": {
                 "type": "record",
                 "name": "baz",
                 "fields": [
                   {
                     "name": "quux",
                     "type": "int"
                   }
                 ]
               }
             }
           ]
         }
       }
     ]
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Invalid canonical form parsing in some situations when array items has an inlined record type [avro-rs]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g closed issue #292: Invalid canonical form parsing in some situations when array items has an inlined record type
URL: https://github.com/apache/avro-rs/issues/292


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Invalid canonical form parsing in some situations when array items has an inlined record type [avro-rs]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on issue #292:
URL: https://github.com/apache/avro-rs/issues/292#issuecomment-3351145939

   The following schema works fine:
   ```rust
   let raw_schema = r#"{
                     "type": "array",
                     "items": {
                         "name": "foo",
                         "type": "record",
                         "fields": [
                             {
                                 "name": "bar",
                                 "type": {
                                     "type": "array",
                                     "items": {
                                         "type": "record",
                                         "name": "baz",
                                         "fields": [
                                             {
                                                 "name": "quux",
                                                 "type": "int"
                                             }
                                         ]
                                     }
                                 }
                             }
                         ]
                     }
                 }"#;
   ```
   
   Notice:
   ```
    "type": {
                                     "type": "array",
                                     "items": {
   ```
   
   I will debug why the reported schema leads to problems. Its `items` is not recognized and it is stored as custom_attributes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Invalid canonical form parsing in some situations when array items has an inlined record type [avro-rs]

Posted by "vkopio (via GitHub)" <gi...@apache.org>.
vkopio commented on issue #292:
URL: https://github.com/apache/avro-rs/issues/292#issuecomment-3317869017

   > Did it work correctly in 0.19.0 ? I.e. is there a regression in 0.20.0 ? Or you just tried it with 0.20.0 for a first time ?
   
   I tested this only using `0.20.0`. I mentioned the version for the sake of reproducibility, but should have been more clear.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Invalid canonical form parsing in some situations when array items has an inlined record type [avro-rs]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on issue #292:
URL: https://github.com/apache/avro-rs/issues/292#issuecomment-3314884053

   Thanks for the report!
   I'll try to find some time to debug it soon!
   The problem seems to be around `"... type":{"type":"array","items":"baz"},"items":{"name":"baz"...`
   
   > I noticed that with version `0.20.0` when a schema has an array with an inlined record in the `items` field, the canonical form parsing will produce an invalid schema in certain situations.
   
   Did it work correctly in 0.19.0 ? I.e. is there a regression in 0.20.0 ?
   Or you just tried it with 0.20.0 for a first time ?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org