-
Notifications
You must be signed in to change notification settings - Fork 2
Eli 595 #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eli 595 #614
Changes from all commits
5f6ef58
5a7d720
0bb1fb6
59734d1
cfc0ec7
a394d35
115f2a3
3e91c9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -97,6 +97,46 @@ def transform_actions_mapper(cls, action_mapper: ActionsMapper) -> ActionsMapper | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action_mapper.root = new_root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return action_mapper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @model_validator(mode="after") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def validate_rule_cohort_labels_against_iteration_cohorts(self) -> typing.Self: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| allowed_labels = {c.cohort_label for c in self.iteration_cohorts} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line_errors: list[InitErrorDetails] = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Pre compute allowed label string once | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| allowed_str = ", ".join(sorted(allowed_labels)) if allowed_labels else None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for idx, rule in enumerate(self.iteration_rules): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not rule.cohort_label: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for label in rule.parsed_cohort_labels: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if label in allowed_labels: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build error message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| error_message = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Invalid cohort_label value '{label}'. Allowed values: {allowed_str}." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if allowed_str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Invalid cohort_label value '{label}'. " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "No iteration cohorts are defined, so no labels are allowed." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line_errors.append( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| InitErrorDetails( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type="value_error", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| loc=("iteration_rules", idx, "cohort_label"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input=rule.cohort_label, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx={"error": error_message}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if line_errors: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValidationError.from_exception_data(title="IterationValidation", line_errors=line_errors) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+104
to
+137
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for idx, rule in enumerate(self.iteration_rules): | |
| if rule.cohort_label is None: | |
| continue | |
| if not all(label in allowed_labels for label in rule.parsed_cohort_labels): | |
| allowed_str = ", ".join(sorted(allowed_labels)) | |
| msg = ( | |
| f"Invalid cohort_label value: {rule.cohort_label}. Allowed values: {allowed_str}. Rule index: {idx}" | |
| ) | |
| raise ValueError(msg) | |
| line_errors: list[InitErrorDetails] = [] | |
| for idx, rule in enumerate(self.iteration_rules): | |
| if rule.cohort_label is None: | |
| continue | |
| for label in rule.parsed_cohort_labels: | |
| if label not in allowed_labels: | |
| allowed_str = ", ".join(sorted(allowed_labels)) | |
| error = InitErrorDetails( | |
| type="value_error", | |
| loc=("iteration_rules", idx, "cohort_label"), | |
| input=rule.cohort_label, | |
| ctx={ | |
| "error": f"Invalid cohort_label value '{label}'. Allowed values: {allowed_str}." | |
| }, | |
| ) | |
| line_errors.append(error) | |
| if line_errors: | |
| raise ValidationError.from_exception_data(title="IterationValidation", line_errors=line_errors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is a separate
@model_validator(mode="after")that raises immediately, any subsequentmode="after"validations (e.g.action_mapper_validation) will not run when cohort-label errors exist. This is a regression in error aggregation/UX compared to the existing pattern that collects multiple validation errors before raising. Consider folding this check into the existingaction_mapper_validationaggregator (or otherwise combining model-level checks) so callers can receive all validation issues in one response.