Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/errors/validation_exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl ValidationError {
}

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

fn maybe_add_cause(self_: PyRef<'_, Self>, py: Python) -> Option<PyErr> {
Expand Down
10 changes: 8 additions & 2 deletions tests/validators/test_with_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,18 @@ def val_func(v: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> Any:
validator = SchemaValidator(
core_schema.with_default_schema(core_schema.no_info_wrap_validator_function(val_func, core_schema.int_schema()))
)
with pytest.raises(SchemaError, match='Uncaught UseDefault error, please check your usage of `default` validators'):
with pytest.raises(
SchemaError,
match='Uncaught `PydanticUseDefault` exception: the error was raised in a field validator and no default value is available for that field.',
):
validator.validate_python('')

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


Expand Down
Loading