-
Notifications
You must be signed in to change notification settings - Fork 0
460: fix: Enum and Fixed would put default in custom_attributes
#47
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -294,19 +294,23 @@ impl FixedSchema { | |||||||||
| S: Serializer, | ||||||||||
| { | ||||||||||
| map.serialize_entry("type", "fixed")?; | ||||||||||
| if let Some(ref n) = self.name.namespace { | ||||||||||
| if let Some(n) = self.name.namespace.as_ref() { | ||||||||||
| map.serialize_entry("namespace", n)?; | ||||||||||
| } | ||||||||||
| map.serialize_entry("name", &self.name.name)?; | ||||||||||
| if let Some(ref docstr) = self.doc { | ||||||||||
| if let Some(docstr) = self.doc.as_ref() { | ||||||||||
| map.serialize_entry("doc", docstr)?; | ||||||||||
| } | ||||||||||
| map.serialize_entry("size", &self.size)?; | ||||||||||
|
|
||||||||||
| if let Some(ref aliases) = self.aliases { | ||||||||||
| if let Some(aliases) = self.aliases.as_ref() { | ||||||||||
| map.serialize_entry("aliases", aliases)?; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if let Some(default) = self.default.as_ref() { | ||||||||||
| map.serialize_entry("default", default)?; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| for attr in &self.attributes { | ||||||||||
| map.serialize_entry(attr.0, attr.1)?; | ||||||||||
| } | ||||||||||
|
|
@@ -783,7 +787,7 @@ impl Serialize for Schema { | |||||||||
| doc, | ||||||||||
| fields, | ||||||||||
| attributes, | ||||||||||
| .. | ||||||||||
| lookup: _lookup, | ||||||||||
| }) => { | ||||||||||
| let mut map = serializer.serialize_map(None)?; | ||||||||||
| map.serialize_entry("type", "record")?; | ||||||||||
|
|
@@ -808,7 +812,8 @@ impl Serialize for Schema { | |||||||||
| symbols, | ||||||||||
| aliases, | ||||||||||
| attributes, | ||||||||||
| .. | ||||||||||
| default, | ||||||||||
| doc, | ||||||||||
| }) => { | ||||||||||
| let mut map = serializer.serialize_map(None)?; | ||||||||||
| map.serialize_entry("type", "enum")?; | ||||||||||
|
|
@@ -821,6 +826,12 @@ impl Serialize for Schema { | |||||||||
| if let Some(aliases) = aliases { | ||||||||||
| map.serialize_entry("aliases", aliases)?; | ||||||||||
| } | ||||||||||
| if let Some(default) = default { | ||||||||||
| map.serialize_entry("default", default)?; | ||||||||||
| } | ||||||||||
| if let Some(doc) = doc { | ||||||||||
| map.serialize_entry("doc", doc)?; | ||||||||||
| } | ||||||||||
| for attr in attributes { | ||||||||||
| map.serialize_entry(attr.0, attr.1)?; | ||||||||||
| } | ||||||||||
|
|
@@ -5147,6 +5158,58 @@ mod tests { | |||||||||
| error, | ||||||||||
| Details::ParsePrimitiveSimilar("bool".to_string(), "boolean").to_string() | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| Ok(()) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[test] | ||||||||||
| fn avro_rs_460_fixed_default_in_custom_attributes() -> TestResult { | ||||||||||
| let schema = Schema::parse_str( | ||||||||||
| r#"{ | ||||||||||
| "name": "fixed_with_default", | ||||||||||
| "type": "fixed", | ||||||||||
| "size": 1, | ||||||||||
| "default": "\u0000", | ||||||||||
| "doc": "a docstring" | ||||||||||
| }"#, | ||||||||||
| )?; | ||||||||||
|
|
||||||||||
| assert_eq!(schema.custom_attributes().unwrap(), &BTreeMap::new()); | ||||||||||
|
|
||||||||||
| let json = serde_json::to_string(&schema)?; | ||||||||||
| let schema2 = Schema::parse_str(&json)?; | ||||||||||
|
|
||||||||||
| let Schema::Fixed(fixed) = schema2 else { | ||||||||||
| panic!("Expected Schema::Fixed, got {schema2:?}"); | ||||||||||
| }; | ||||||||||
| assert!(fixed.default.is_some()); | ||||||||||
|
|
||||||||||
| Ok(()) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[test] | ||||||||||
| fn avro_rs_460_enum_default_in_custom_attributes() -> TestResult { | ||||||||||
| let schema = Schema::parse_str( | ||||||||||
| r#"{ | ||||||||||
| "name": "fixed_with_default", | ||||||||||
| "type": "enum", | ||||||||||
| "symbols": ["A", "B", "C"], | ||||||||||
| "default": "A", | ||||||||||
| "doc": "a docstring" | ||||||||||
| }"#, | ||||||||||
| )?; | ||||||||||
|
|
||||||||||
| assert_eq!(schema.custom_attributes().unwrap(), &BTreeMap::new()); | ||||||||||
|
|
||||||||||
| let json = serde_json::to_string(&schema)?; | ||||||||||
| let schema2 = Schema::parse_str(&json)?; | ||||||||||
|
|
||||||||||
| let Schema::Enum(enum_schema) = schema2 else { | ||||||||||
| panic!("Expected Schema::Fixed, got {schema2:?}"); | ||||||||||
|
Comment on lines
+5207
to
+5208
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy-paste error in panic message. The panic message says "Expected Schema::Fixed" but this test is checking for Proposed fix- panic!("Expected Schema::Fixed, got {schema2:?}");
+ panic!("Expected Schema::Enum, got {schema2:?}");📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:useful; category:bug; feedback: The CodeRabbit AI is correct! The panic message is copied from the unit test for Fixed schema. It should be fixed to say Enum instead! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:useful; category:bug; feedback: The Augment AI is correct! The panic message is copied from the unit test for Fixed schema. It should be fixed to say Enum instead! |
||||||||||
| }; | ||||||||||
| assert!(enum_schema.default.is_some()); | ||||||||||
| assert!(enum_schema.doc.is_some()); | ||||||||||
|
|
||||||||||
| Ok(()) | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -690,7 +690,7 @@ impl Parser { | |
| doc: complex.doc(), | ||
| symbols, | ||
| default, | ||
| attributes: self.get_custom_attributes(complex, vec!["symbols"]), | ||
| attributes: self.get_custom_attributes(complex, vec!["symbols", "default"]), | ||
| }); | ||
|
|
||
| self.register_parsed_schema(&fully_qualified_name, &schema, &aliases); | ||
|
|
@@ -792,8 +792,8 @@ impl Parser { | |
| _ => None, | ||
| }); | ||
|
|
||
| if default.is_some() { | ||
| let len = default.clone().unwrap().len(); | ||
| if let Some(default) = &default { | ||
| let len = default.len(); | ||
| if len != size as usize { | ||
| return Err(Details::FixedDefaultLenSizeMismatch(len, size).into()); | ||
| } | ||
|
|
@@ -809,7 +809,7 @@ impl Parser { | |
| doc, | ||
| size: size as usize, | ||
| default, | ||
| attributes: self.get_custom_attributes(complex, vec!["size"]), | ||
| attributes: self.get_custom_attributes(complex, vec!["size", "default"]), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-but-wont-fix; category:bug; feedback: The Augment AI says that the value should be a String, but https://avro.apache.org/docs/1.12.0/specification/#fixed does not mention "default" field for Fixed schema at all. For Array schema the default field has JSON array type - https://avro.apache.org/docs/1.12.0/specification/#arrays. The same could be used for Fixed too if Fixed could have a default. |
||
| }); | ||
|
|
||
| self.register_parsed_schema(&fully_qualified_name, &schema, &aliases); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The panic message here seems to be copy-pasted from the
avro_rs_460_fixed_default_in_custom_attributestest. It should refer toSchema::Enuminstead ofSchema::Fixedto be accurate for this test case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value:useful; category:bug; feedback: The Gemini AI is correct! The panic message is copied from the unit test for Fixed schema. It should be fixed to say Enum instead!