Skip to content

Commit ef455b4

Browse files
authored
Improve uncaught PydanticUseDefault exception message (#1730)
1 parent 0b898d2 commit ef455b4

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/errors/validation_exception.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl ValidationError {
110110
}
111111

112112
pub fn use_default_error() -> PyErr {
113-
py_schema_error_type!("Uncaught UseDefault error, please check your usage of `default` validators.")
113+
py_schema_error_type!("Uncaught `PydanticUseDefault` exception: the error was raised in a field validator and no default value is available for that field.")
114114
}
115115

116116
fn maybe_add_cause(self_: PyRef<'_, Self>, py: Python) -> Option<PyErr> {

tests/validators/test_with_default.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,18 @@ def val_func(v: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> Any:
627627
validator = SchemaValidator(
628628
core_schema.with_default_schema(core_schema.no_info_wrap_validator_function(val_func, core_schema.int_schema()))
629629
)
630-
with pytest.raises(SchemaError, match='Uncaught UseDefault error, please check your usage of `default` validators'):
630+
with pytest.raises(
631+
SchemaError,
632+
match='Uncaught `PydanticUseDefault` exception: the error was raised in a field validator and no default value is available for that field.',
633+
):
631634
validator.validate_python('')
632635

633636
# same if there is no WithDefault validator
634637
validator = SchemaValidator(core_schema.no_info_wrap_validator_function(val_func, core_schema.int_schema()))
635-
with pytest.raises(SchemaError, match='Uncaught UseDefault error, please check your usage of `default` validators'):
638+
with pytest.raises(
639+
SchemaError,
640+
match='Uncaught `PydanticUseDefault` exception: the error was raised in a field validator and no default value is available for that field.',
641+
):
636642
validator.validate_python('')
637643

638644

0 commit comments

Comments
 (0)