Skip to content

Commit 2fd830d

Browse files
attribute name is optional only for cohort attribte level
1 parent 69473d1 commit 2fd830d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/eligibility_signposting_api/model/campaign_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ def parse_yn_to_bool(cls, v: str | bool) -> bool: # noqa: N805
163163
return v.upper() == "Y"
164164
return v
165165

166+
@model_validator( mode="after")
167+
def validate_attribute_name_is_optional_only_for_cohort_attribute_level(self) -> typing.Self: # noqa: N805
168+
if self.attribute_name:
169+
return self
170+
else:
171+
if self.attribute_level == RuleAttributeLevel.COHORT:
172+
return self
173+
else:
174+
raise ValueError(f"AttributeName must be set for {self.attribute_level} AttributeLevel.")
175+
176+
166177
_parent: Iteration | None = PrivateAttr(default=None)
167178

168179
def set_parent(self, parent: Iteration) -> None:

0 commit comments

Comments
 (0)