Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions infrahub_sdk/convert_object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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