This is an automated email from the ASF dual-hosted git repository.

kriskras99 pushed a commit to branch feat/schema_aware_ser_and_deser
in repository https://gitbox.apache.org/repos/asf/avro-rs.git


The following commit(s) were added to 
refs/heads/feat/schema_aware_ser_and_deser by this push:
     new 80a1d88  fix: Don't call `T::field_default()` if the schema is 
overwritten using `#[avro(with)]`
80a1d88 is described below

commit 80a1d88a905ddce5beb7cbb6f2305edfd0830c6c
Author: default <[email protected]>
AuthorDate: Fri Mar 20 12:11:18 2026 +0000

    fix: Don't call `T::field_default()` if the schema is overwritten using 
`#[avro(with)]`
---
 avro/src/serde/with.rs            | 12 ++++++------
 avro_derive/src/attributes/mod.rs |  6 ++++++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/avro/src/serde/with.rs b/avro/src/serde/with.rs
index 893940e..db32a5a 100644
--- a/avro/src/serde/with.rs
+++ b/avro/src/serde/with.rs
@@ -510,10 +510,10 @@ pub mod slice_opt {
 ///
 /// See usage with below example:
 /// ```
-/// # use apache_avro::AvroSchema;
+/// # use apache_avro::{AvroSchema, BigDecimal};
 /// # use serde::{Deserialize, Serialize};
 /// #[derive(AvroSchema, Serialize, Deserialize)]
-/// struct StructWithBigDecimal<'a> {
+/// struct StructWithBigDecimal {
 ///     #[avro(with)]
 ///     #[serde(with = "apache_avro::serde::bigdecimal")]
 ///     decimal: BigDecimal,
@@ -582,10 +582,10 @@ pub mod bigdecimal {
 ///
 /// See usage with below example:
 /// ```
-/// # use apache_avro::AvroSchema;
+/// # use apache_avro::{AvroSchema, BigDecimal};
 /// # use serde::{Deserialize, Serialize};
 /// #[derive(AvroSchema, Serialize, Deserialize)]
-/// struct StructWithBigDecimal<'a> {
+/// struct StructWithBigDecimal {
 ///     #[avro(with)]
 ///     #[serde(with = "apache_avro::serde::bigdecimal_opt")]
 ///     decimal: Option<BigDecimal>,
@@ -664,7 +664,7 @@ pub mod bigdecimal_opt {
 /// # use apache_avro::AvroSchema;
 /// # use serde::{Deserialize, Serialize};
 /// #[derive(AvroSchema, Serialize, Deserialize)]
-/// struct StructWithBytes<'a> {
+/// struct StructWithArray {
 ///     #[avro(with = apache_avro::serde::array::get_schema_in_ctxt::<i32>)]
 ///     #[serde(with = "apache_avro::serde::array")]
 ///     array: [i32; 10],
@@ -738,7 +738,7 @@ pub mod array {
 /// # use apache_avro::AvroSchema;
 /// # use serde::{Deserialize, Serialize};
 /// #[derive(AvroSchema, Serialize, Deserialize)]
-/// struct StructWithBytes<'a> {
+/// struct StructWithArray {
 ///     #[avro(with = 
apache_avro::serde::array_opt::get_schema_in_ctxt::<i32>)]
 ///     #[serde(with = "apache_avro::serde::array_opt")]
 ///     array: Option<[i32; 10]>,
diff --git a/avro_derive/src/attributes/mod.rs 
b/avro_derive/src/attributes/mod.rs
index 27c1cbc..78c55b4 100644
--- a/avro_derive/src/attributes/mod.rs
+++ b/avro_derive/src/attributes/mod.rs
@@ -340,6 +340,12 @@ impl FieldOptions {
             return Err(errors);
         }
 
+        // TODO: Implement a better way to do this (maybe if user specifies 
`#[avro(with)]` also use that for the default)
+        // Disable getting the field default, if the schema is not retrieved 
from the field type
+        if with != With::Trait && avro.default == FieldDefault::Trait {
+            avro.default = FieldDefault::Disabled;
+        }
+
         let doc = avro.doc.or_else(|| extract_rustdoc(attributes));
 
         Ok(Self {

Reply via email to