Skip to content

Commit 6cdd780

Browse files
authored
Add to object conversion input (#558)
1 parent 840d98a commit 6cdd780

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

infrahub_sdk/convert_object_type.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def check_only_one_field(self) -> ConversionFieldValue:
3636
fields = [self.attribute_value, self.peer_id, self.peers_ids]
3737
set_fields = [f for f in fields if f is not None]
3838
if len(set_fields) != 1:
39-
raise ValueError("Exactly one of attribute_value, peer_id, or peers_ids must be set")
39+
raise ValueError("Exactly one of `attribute_value`, `peer_id`, or `peers_ids` must be set")
4040
return self
4141

4242

@@ -45,16 +45,17 @@ class ConversionFieldInput(BaseModel):
4545
Indicates how to fill in the value of the destination field during an object conversion.
4646
Use `source_field` to reuse the value of the corresponding field of the object being converted.
4747
Use `data` to specify the new value for the field.
48-
Only one of `source_field` or `data` can be specified.
48+
Use `use_default_value` to set the destination field to its schema default.
49+
Only one of `source_field`, `data`, or `use_default_value` can be specified.
4950
"""
5051

5152
source_field: str | None = None
5253
data: ConversionFieldValue | None = None
54+
use_default_value: bool = False
5355

5456
@model_validator(mode="after")
5557
def check_only_one_field(self) -> ConversionFieldInput:
56-
if self.source_field is not None and self.data is not None:
57-
raise ValueError("Only one of source_field or data can be set")
58-
if self.source_field is None and self.data is None:
59-
raise ValueError("Either source_field or data must be set")
58+
fields_set = [self.source_field is not None, self.data is not None, self.use_default_value is True]
59+
if sum(fields_set) != 1:
60+
raise ValueError("Exactly one of `source_field`, `data` or `use_default_value` must be set")
6061
return self

0 commit comments

Comments
 (0)