Skip to content

Commit ac9c806

Browse files
committed
Updates custom error messages
1 parent 113729f commit ac9c806

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

RATapi/controls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def warn_setting_incorrect_properties(self, handler: ValidatorFunctionWrapHandle
155155
f" controls procedure are:\n "
156156
f"{', '.join(fields.get('procedure', []))}\n",
157157
}
158-
custom_error_list = custom_pydantic_validation_error(exc.errors(), custom_error_msgs)
158+
custom_error_list = custom_pydantic_validation_error(exc.errors(include_url=False), custom_error_msgs)
159159
raise ValidationError.from_exception_data(exc.title, custom_error_list, hide_input=True) from None
160160

161161
if isinstance(model_input, validated_self.__class__):

RATapi/project.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,13 +649,15 @@ def check_allowed_values(self, attribute: str, field_list: list[str], allowed_va
649649
650650
"""
651651
class_list = getattr(self, attribute)
652-
for model in class_list:
652+
for index, model in enumerate(class_list):
653653
for field in field_list:
654654
value = getattr(model, field, "")
655655
if value and value not in allowed_values:
656656
raise ValueError(
657-
f'The value "{value}" in the "{field}" field of "{attribute}" must be defined in '
658-
f'"{values_defined_in[f"{attribute}.{field}"]}".',
657+
f'The value "{value}" used in the "{field}" field at index {index} of "{attribute}" '
658+
f'must be defined in "{values_defined_in[f"{attribute}.{field}"]}". Please either add '
659+
f'"{value}" to "{values_defined_in[f"{attribute}.{field}"]}" before including it in'
660+
f' "{attribute}", or remove it from "{attribute}.{field}" before attempting to delete it.',
659661
)
660662

661663
def check_allowed_source(self, attribute: str) -> None:
@@ -945,7 +947,7 @@ def wrapped_func(*args, **kwargs):
945947
Project.model_validate(self)
946948
except ValidationError as exc:
947949
class_list.data = previous_state
948-
custom_error_list = custom_pydantic_validation_error(exc.errors())
950+
custom_error_list = custom_pydantic_validation_error(exc.errors(include_url=False))
949951
raise ValidationError.from_exception_data(exc.title, custom_error_list, hide_input=True) from None
950952
except (TypeError, ValueError):
951953
class_list.data = previous_state

RATapi/utils/custom_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def custom_pydantic_validation_error(
3535
if error["type"] in custom_error_msgs:
3636
custom_error = pydantic_core.PydanticCustomError(error["type"], custom_error_msgs[error["type"]])
3737
else:
38-
custom_error = pydantic_core.PydanticCustomError(error["type"], error["msg"])
38+
custom_error = pydantic_core.PydanticCustomError(error["type"], error["msg"].replace(",", ":", 1))
3939
error["type"] = custom_error
4040
custom_error_list.append(error)
4141

0 commit comments

Comments
 (0)