Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Not A Problem
-
None
-
None
Description
Schema validation fails when referencing a previously defined type which has inherited a namespace.
Schema:
{ "type": "record", "name": "Foo", "namespace": "name.space", "fields": [ { "name": "barInit", "type": { "type": "enum", "name": "Bar", "symbols": [ "bar0", "bar1" ] } }, { "name": "barUse", "type": "Bar" } ] }
Rust Objects (from rsgen)
#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Clone, serde::Deserialize, serde::Serialize,)] pub enum Bar { #[serde(rename = "bar0")] Bar0, #[serde(rename = "bar1")] Bar1, } #[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize, serde::Serialize)] pub struct Foo { #[serde(rename = "barInit")] pub bar_init: Bar, #[serde(rename = "barUse")] pub bar_use: Bar, }
Test
#[test] fn test_serialize() { testing_logger::setup(); let schema = Schema::parse_str(&get_raw_example_schema()).unwrap(); let foo = Foo { bar_init: Bar::Bar0, bar_use: Bar::Bar1, }; let avro_value = to_value(foo).unwrap(); println!( "value is valid for schema: {}", avro_value.validate(&schema) ); testing_logger::validate(|logs| { for log in logs { println!("{}", log.body) } }); let mut writer = Writer::new(&schema, Vec::new()); // schema validation happens here writer.append(avro_value).unwrap(); }
Test & Log Output
value is valid for schema: false Invalid value: Record([("barInit", Enum(0, "bar0")), ("barUse", Enum(1, "bar1"))]) for schema: Record { name: Name { name: "Foo", namespace: Some("name.space") }, aliases: None, doc: None, fields: [RecordField { name: "barInit", doc: None, default: None, schema: Enum { name: Name { name: "Bar", namespace: None }, aliases: None, doc: None, symbols: ["bar0", "bar1"] }, order: Ascending, position: 0 }, RecordField { name: "barUse", doc: None, default: None, schema: Ref { name: Name { name: "Bar", namespace: None } }, order: Ascending, position: 1 }], lookup: {"barInit": 0, "barUse": 1} }. Reason: Unresolved schema reference: 'Bar'. Parsed names: [Name { name: "Bar", namespace: Some("name.space") }, Name { name: "Foo", namespace: Some("name.space") }] thread 'test::test_serialize' panicked at 'called `Result::unwrap()` on an `Err` value: ValidationWithReason("Unresolved schema reference: 'Bar'. Parsed names: [Name { name: \"Foo\", namespace: Some(\"name.space\") }, Name { name: \"Bar\", namespace: Some(\"name.space\") }]")', src/main.rs:33:35
full test repo is attached
Attachments
Attachments
Issue Links
- links to