-
Notifications
You must be signed in to change notification settings - Fork 34
Issue #252: Add an Option<String>
field with a #[avro(default = "null")]
#260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ull")]` #252 (comment) Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Hm!
while it should be I see two ways to improve/fix it:
|
Shouldn't it only parse |
Yes! Debugging confirms this. But still the default's value must be |
I think the bug is in the schema generated. It should be |
(Note that when a default value is specified for a record field whose type is a union, the type of the default value must match the first element of the union. Thus, for unions containing “null”, the “null” is usually listed first, since the default value of such unions is typically null.) |
So thinking about it for a bit, there are two bugs:
|
It does produce serde_json::Value::Null |
But that should generate a |
Yes! There is a bug somewhere! Lines 7203 to 7226 in 23a9af7
so it seems to be somewhere in the derive macro... |
I think the bug is in schema_equality.rs |
Right! The default equality (SpecificationEq) uses the canonical form of the schema and as we already know the |
It should be `null` instead of `"null"` Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Another bug: the default equality impl is |
Well, I am not sure whether it is a bug or not. |
Looking at StructFieldEq it doesn't seem to check the default field |
…sage Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
I think the only way to compare this would be with |
Or change StructFieldEq to also look at default (and potentially other things like doc) |
Right! git diff
diff --git i/avro/src/schema_equality.rs w/avro/src/schema_equality.rs
index 1097594..83bf969 100644
--- i/avro/src/schema_equality.rs
+++ w/avro/src/schema_equality.rs
@@ -217,7 +217,9 @@ impl StructFieldEq {
&& fields_one
.iter()
.zip(fields_two.iter())
- .all(|(f1, f2)| self.compare(&f1.schema, &f2.schema))
+ .all(|(f1, f2)| {
+ self.compare(&f1.schema, &f2.schema) && f1.default == f2.default
+ })
}
}
diff --git i/avro_derive/tests/derive.rs w/avro_derive/tests/derive.rs
index a85caa0..aea426f 100644
--- i/avro_derive/tests/derive.rs
+++ w/avro_derive/tests/derive.rs
@@ -1449,7 +1449,7 @@ mod test_derive {
{
"name":"optional",
"type": ["null", "string"],
- "default": null
+ "default": "null"
}
] detects the issue! Hopefully someone will explain why the |
Hmmm. I think I understand why For our testing purposes it's probably better to use something like this: fn strict_schema_equality(expected: &str, schema: Schema) {
let expected: Value = serde_json::from_str(expected).unwrap();
let got = serde_json::to_value(schema).unwrap();
assert_eq!(got, expected)
} This checks that all fields are as expected, including doc, default and other fields. |
Extend the test case with an Option field with a default.
#252 (comment)