@@ -159,7 +159,6 @@ class Other:
159159
160160
161161def test_serialize_with_recursive_models () -> None :
162-
163162 class Node :
164163 next : Optional ['Node' ] = None
165164 value : int = 42
@@ -171,12 +170,12 @@ class Node:
171170 Node ,
172171 core_schema .model_fields_schema (
173172 {
174- 'value' : core_schema .model_field (core_schema .with_default_schema (core_schema .int_schema (), default = 42 )),
173+ 'value' : core_schema .model_field (
174+ core_schema .with_default_schema (core_schema .int_schema (), default = 42 )
175+ ),
175176 'next' : core_schema .model_field (
176177 core_schema .with_default_schema (
177- core_schema .nullable_schema (
178- core_schema .definition_reference_schema ('Node' )
179- ),
178+ core_schema .nullable_schema (core_schema .definition_reference_schema ('Node' )),
180179 default = None ,
181180 )
182181 ),
@@ -187,7 +186,12 @@ class Node:
187186 ],
188187 )
189188
190- s = SchemaSerializer (schema )
191- v = SchemaValidator (schema )
189+ Node .__pydantic_core_schema__ = schema
190+ Node .__pydantic_validator__ = SchemaValidator (Node .__pydantic_core_schema__ )
191+ Node .__pydantic_serializer__ = SchemaSerializer (Node .__pydantic_core_schema__ )
192+ other = Node .__pydantic_validator__ .validate_python ({'next' : {'value' : 4 }})
192193
193- obj = v .validate_python ({'value' : 2 , 'asdas' : 1 })
194+ assert Node .__pydantic_serializer__ .to_python (other , serialize_as_any = True ) == {
195+ 'next' : {'next' : None , 'value' : 4 },
196+ 'value' : 42 ,
197+ }
0 commit comments