Skip to content

Wrong field is parsed when the "logicalType": "uuid" value is set on a field #185

@edude03

Description

@edude03

So this is a strange issue. It seems like if "logicalType": "uuid" is set, it parses the value next field instead of the existing one.

Take a look at this example:

use uuid::Uuid;
use std::str::FromStr;
use serde::{Serialize};
use avro_rs::{Reader, Writer, Schema};

#[derive(Debug, Serialize)]
struct Event {
    id: Uuid,
    event_type: String
}

fn main() {
    let raw_schema = r#"
    {
        "type": "record",
        "namespace": "something",
        "name": "TimelineEvent",
        "fields": [{
            "name": "id",
            "type": "string",
            "logicalType": "uuid"
        }, {
            "name": "event_type",
            "type": "string"
        }]
    }
    "#;

    let schema = Schema::parse_str(raw_schema).unwrap();

    let e = Event {
        id: Uuid::from_str("596a6c76-b398-4458-8b25-e5451850a7da").unwrap(),
        event_type: "user_created".to_string()
    };

    let mut writer = Writer::new(&schema, Vec::new());
    writer.append_ser(&e).unwrap();

    let serialized = writer.into_inner().unwrap();

    let reader = Reader::new(&serialized[..]).unwrap();

    for v in reader {
        println!("The length of the next field (event_type) is {:?}", &e.event_type.len());
        println!("{:?}", v.unwrap());
    }
}

Which produces:

Finished dev [unoptimized + debuginfo] target(s) in 1.21s
     Running `target/debug/avro-bug-repro`
The length of the next field (event_type) is 12
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ConvertStrToUuid(Error(Parser(InvalidLength { expected: Any([36, 32]), found: 12 })))', src/main.rs:46:28
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Removing the logical type "fixes" this issue, but I guess that's not really the solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions