diff --git a/src/validators/definitions.rs b/src/validators/definitions.rs index e0511f7fe..aeeb627ac 100644 --- a/src/validators/definitions.rs +++ b/src/validators/definitions.rs @@ -92,6 +92,18 @@ impl Validator for DefinitionRefValidator { }) } + fn default_value<'py>( + &self, + _py: Python<'py>, + _outer_loc: Option>, + _state: &mut ValidationState<'_, 'py>, + ) -> ValResult> { + self.definition.read(|validator| { + let validator = validator.unwrap(); + validator.default_value(_py, _outer_loc, _state) + }) + } + fn validate_assignment<'py>( &self, py: Python<'py>, diff --git a/tests/validators/test_definitions.py b/tests/validators/test_definitions.py index 18101fa93..d4102e95a 100644 --- a/tests/validators/test_definitions.py +++ b/tests/validators/test_definitions.py @@ -150,3 +150,17 @@ def test_definition_chain(): ), ) assert v.validate_python('1') == 1 + + +def test_forwards_get_default_value(): + v = SchemaValidator( + core_schema.definitions_schema( + core_schema.definition_reference_schema('foo'), + [core_schema.with_default_schema(core_schema.int_schema(), default=1, ref='foo')], + ) + ) + + default = v.get_default_value() + + assert default is not None + assert default.value == 1