You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Schema type for Uuid type is overridden by set_serde_human_readable() parameter on serialization #440
A uuid logical type annotates an Avro string or fixed of length 16.
However, in the current mainline (#6218cd7) schema requirements for underlying type are ignored on uuids serialisation, and the type depends on apache_avro::util::set_serde_human_readable() parameter: when true uuids are serialised into strings, when false - into bytes.
This behaviour differs from latest released version rel/release-0.21.0, where the type depends on the schema.
It seems the behaviour from rel/release-0.21.0 is more correct. Could it be restored?
Attaching here an integration test for convenience.
use apache_avro::{Reader,Schema,Uuid,Writer};use std::error::Error;#[test]fntest_uuid_serliazation_deserialization() -> Result<(),Box<dynError>>{// This line makes the test to pass.// Currently it's passigng only with `set_serde_human_readable(true)`// It worked correctly both with `true` an `false in `rel/release-0.21.0`.// apache_avro::util::set_serde_human_readable(true);let raw_schema = r#" { "name": "uuid", "type": "string", "logicalType": "uuid" } "#;let schema = Schema::parse_str(raw_schema)?;let initial_id = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000")?;letmut writer = Writer::new(&schema,Vec::new())?;
writer.append_ser(&initial_id)?;let input = writer.into_inner()?;let reader = Reader::with_schema(&schema,&input[..])?;for value in reader {println!("{value:?}");assert_eq!(initial_id, apache_avro::from_value::<Uuid>(&value?)?);}Ok(())}
It did not work correctly in 0.21.0 (and before).
If serde_human_readable was set to true it would allways output a string (even if the schema was bytes) and if it was set to false it would always output a bytes (not a fixed!):
human_readable
Uuid
true
string
false
bytes
In 0.22.0 it will do the following:
human_readable
Uuid (String)
Uuid (Bytes)
Uuid (Fixed)
true
string
Err
Err
false
bytes*
bytes
fixed
* This is a bug and will be fixed, it should be Err
What you want is not possible. We don't get a Uuid from Serde. We get a string if human_readable is true (like 550e8400-e29b-41d4-a716-446655440000) or we bytes when human_readable is false (like [171, 27, 146, 24, 38, 212, 254, 206, 21, 172, 18, 139, 191, 244, 27, 226]). So we can't choose the input to match what the schema expects.
Hi @Kriskras99, technically the serialization result is defined not by serde, but by uuid crate here, but I see what you mean.
So just to understand, the expected behaviour is to produce errors when schema and serialisation results don't match?
Additionally, do you see a custom Serialize implementation (for an struct with Uuid field for example) as a good way to ensure the serialisation result is aligned with the schema for both serde_human_readabletrue and false?
Activity
Kriskras99 commentedon Jan 26, 2026
It did not work correctly in 0.21.0 (and before).
If
serde_human_readablewas set totrueit would allways output a string (even if the schema was bytes) and if it was set tofalseit would always output a bytes (not a fixed!):truestringfalsebytesIn 0.22.0 it will do the following:
truestringErrErrfalsebytes*bytesfixed* This is a bug and will be fixed, it should be
ErrWhat you want is not possible. We don't get a
Uuidfrom Serde. We get a string ifhuman_readableistrue(like550e8400-e29b-41d4-a716-446655440000) or we bytes whenhuman_readableisfalse(like[171, 27, 146, 24, 38, 212, 254, 206, 21, 172, 18, 139, 191, 244, 27, 226]). So we can't choose the input to match what the schema expects.alambov-md commentedon Jan 26, 2026
Hi @Kriskras99, technically the serialization result is defined not by
serde, but byuuidcrate here, but I see what you mean.So just to understand, the expected behaviour is to produce errors when schema and serialisation results don't match?
Additionally, do you see a custom
Serializeimplementation (for an struct withUuidfield for example) as a good way to ensure the serialisation result is aligned with the schema for bothserde_human_readabletrueandfalse?Kriskras99 commentedon Jan 26, 2026
Yes, that is correct.
Yes, that would be a good option.