You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Rik Heijdens (Jira)" <ji...@apache.org> on 2022/12/13 10:27:00 UTC

[jira] [Created] (AVRO-3688) Schema resolution panics when a custom record field is included multiple times

Rik Heijdens created AVRO-3688:
----------------------------------

             Summary: Schema resolution panics when a custom record field is included multiple times
                 Key: AVRO-3688
                 URL: https://issues.apache.org/jira/browse/AVRO-3688
             Project: Apache Avro
          Issue Type: Bug
            Reporter: Rik Heijdens


Consider the following Avro schema:

{noformat}
{
    "type": "record",
    "name": "Message",
    "fields": [
        {
            "name": "field_a",
            "type": [
                "null",
                {
                    "name": "Inner",
                    "type": "record",
                    "fields": [
                        {
                            "name": "inner_a",
                            "type": "string"
                        }
                    ]
                }
            ],
            "default": null
        },
        {
            "name": "field_b",
            "type": [
                "null",
                "Inner"
            ],
            "default": null
        }
    ]
}{noformat}

This can be represented in Rust through the following structs:

{noformat}
#[derive(Serialize, Deserialize)]
struct Inner {
    inner_a: String
}

#[derive(Serialize, Deserialize)]
struct Message {
    field_a: Option<Inner>,
    field_b: Option<Inner>
}
{noformat}

If I instantiate an instance of `message`, set `field_a` and then serialize it using the following code:

{noformat}
        let schema = Schema::parse_str(&schema_str).unwrap();

        let msg = Message {
            field_a: Some(Inner {
                inner_a: "foo".to_string()
            }),
            field_b: None
        };

        let mut ser = Serializer::default();
        let test_value: Value = msg.serialize(&mut ser).unwrap();
        assert!(test_value.validate(&schema), "test_value should validate");
        assert!(
            test_value.resolve(&schema).is_ok(),
            "test_value should resolve"
        );
{noformat}

Then my assertions pass. However if I set field_b to `Inner`, then my call to `test_value.resolve(&schema)` panics:

{noformat}
let schema = Schema::parse_str(&schema_str).unwrap();

let msg = Message {
    field_a: Some(Inner {
        inner_a: "foo".to_string()
    }),
    field_b: Some(Inner {
        inner_a: "bar".to_string()
    })
};

let mut ser = Serializer::default();
let test_value: Value = msg.serialize(&mut ser).unwrap();
assert!(test_value.validate(&schema), "test_value should validate");
assert!(
    test_value.resolve(&schema).is_ok(),
    "test_value should resolve"
);
{noformat}

This seems to be a bug in the schema resolution logic that's causing an unhandled panic.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)