@@ -87,19 +87,19 @@ impl TableReference {
8787 }
8888}
8989
90- /// Deserializes a `LifeCycle` field that may be present as `null` in JSON.
90+ /// Deserializes a field that may be present as `null` in JSON, falling back to `T::default()` .
9191///
9292/// `MaterializedView` uses `#[serde(rename_all = "camelCase")]`, so the Python SDK's
9393/// `"lifeCycle": null` is recognized as the field (unlike `Table` where the camelCase key is
9494/// simply ignored as unknown). A plain `#[serde(default)]` only applies when the field is
9595/// *absent*; when it's present as `null`, serde would attempt to deserialize `null` as
96- /// `LifeCycle` and fail. This deserializer treats `null` the same as a missing field.
97- fn deserialize_nullable_life_cycle < ' de , D > ( d : D ) -> Result < LifeCycle , D :: Error >
96+ /// the target type and fail. This deserializer treats `null` the same as a missing field.
97+ fn deserialize_nullable_as_default < ' de , D , T > ( d : D ) -> Result < T , D :: Error >
9898where
9999 D : Deserializer < ' de > ,
100+ T : Default + Deserialize < ' de > ,
100101{
101- Option :: < LifeCycle > :: deserialize ( d)
102- . map ( |opt| opt. unwrap_or_else ( LifeCycle :: default_for_deserialization) )
102+ Option :: < T > :: deserialize ( d) . map ( |opt| opt. unwrap_or_default ( ) )
103103}
104104
105105/// Represents a ClickHouse Materialized View.
@@ -141,10 +141,7 @@ pub struct MaterializedView {
141141
142142 /// Lifecycle management policy for the materialized view.
143143 /// Controls whether Moose can drop or modify the MV automatically.
144- #[ serde(
145- default = "LifeCycle::default_for_deserialization" ,
146- deserialize_with = "deserialize_nullable_life_cycle"
147- ) ]
144+ #[ serde( default , deserialize_with = "deserialize_nullable_as_default" ) ]
148145 pub life_cycle : LifeCycle ,
149146}
150147
@@ -485,7 +482,7 @@ mod tests {
485482
486483 let mv_with_db = MaterializedView {
487484 database : Some ( "other_db" . to_string ( ) ) ,
488- ..mv. clone ( )
485+ ..mv
489486 } ;
490487 assert_eq ! ( mv_with_db. id( "default_db" ) , "other_db_my_mv" ) ;
491488 }
0 commit comments