diff --git a/infrahub_sdk/convert_object_type.py b/infrahub_sdk/convert_object_type.py index fe7ee4b5..3e30dd2f 100644 --- a/infrahub_sdk/convert_object_type.py +++ b/infrahub_sdk/convert_object_type.py @@ -36,7 +36,7 @@ def check_only_one_field(self) -> ConversionFieldValue: fields = [self.attribute_value, self.peer_id, self.peers_ids] set_fields = [f for f in fields if f is not None] if len(set_fields) != 1: - raise ValueError("Exactly one of attribute_value, peer_id, or peers_ids must be set") + raise ValueError("Exactly one of `attribute_value`, `peer_id`, or `peers_ids` must be set") return self @@ -45,16 +45,17 @@ class ConversionFieldInput(BaseModel): Indicates how to fill in the value of the destination field during an object conversion. Use `source_field` to reuse the value of the corresponding field of the object being converted. Use `data` to specify the new value for the field. - Only one of `source_field` or `data` can be specified. + Use `use_default_value` to set the destination field to its schema default. + Only one of `source_field`, `data`, or `use_default_value` can be specified. """ source_field: str | None = None data: ConversionFieldValue | None = None + use_default_value: bool = False @model_validator(mode="after") def check_only_one_field(self) -> ConversionFieldInput: - if self.source_field is not None and self.data is not None: - raise ValueError("Only one of source_field or data can be set") - if self.source_field is None and self.data is None: - raise ValueError("Either source_field or data must be set") + fields_set = [self.source_field is not None, self.data is not None, self.use_default_value is True] + if sum(fields_set) != 1: + raise ValueError("Exactly one of `source_field`, `data` or `use_default_value` must be set") return self