Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhly committed Oct 15, 2023
1 parent fd5521c commit 54203aa
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/serializers/computed_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,28 +219,27 @@ fn get_next_value<'a>(
}
_ => Ok(None),
};
let legacy_next_value = match legacy_result {
Ok(res) => res,
match legacy_result {
Ok(opt) => {
if let Some(legacy_next_value) = opt {
return Ok(legacy_next_value);
}
}
Err(err) => return Err(err),
};
if legacy_next_value.is_some() {
return Ok(legacy_next_value.unwrap());
}

// Default behavior: If custom serialization function provided, compute value based on input.
if field.has_ser_func {
return Ok(input_value);
}

// Fallback behavior: Check if computed field is a property of input object.
let property_name = field.property_name_py.as_ref(input_value.py());
if input_value.hasattr(property_name).unwrap_or_default() {
return input_value.getattr(property_name);
}

Err(PydanticSerializationError::new_err(format!(
"No serialization function found for '{}'",
property_name
"No serialization function found for '{property_name}'",
)))
}

Expand Down

0 comments on commit 54203aa

Please sign in to comment.