Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Consider the following Avro schema:
{
"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
}
]
}
This can be represented in Rust through the following structs:
#[derive(Serialize, Deserialize)]
struct Inner {
inner_a: String
}
#[derive(Serialize, Deserialize)]
struct Message {
field_a: Option<Inner>,
field_b: Option<Inner>
}
If I instantiate an instance of `message`, set `field_a` and then serialize it using the following code:
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"
);
Then my assertions pass. However if I set field_b to `Inner`, then my call to `test_value.resolve(&schema)` panics:
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"
);
This seems to be a bug in the schema resolution logic that's causing an unhandled panic.
Attachments
Issue Links
- links to