Skip to content

Commit

Permalink
Fix applying SkipValidation to referenced schemas (#7381)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Sep 8, 2023
1 parent cf35172 commit 9c03680
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pydantic/functional_validators.py
Expand Up @@ -575,6 +575,11 @@ def __get_pydantic_core_schema__(
) -> core_schema.CoreSchema:
original_schema = handler(source)
metadata = _core_metadata.build_metadata_dict(js_annotation_functions=[lambda _c, h: h(original_schema)])
return core_schema.any_schema(metadata=metadata, serialization=original_schema)
return core_schema.any_schema(
metadata=metadata,
serialization=core_schema.wrap_serializer_function_ser_schema(
function=lambda v, h: h(v), schema=original_schema
),
)

__hash__ = object.__hash__
10 changes: 10 additions & 0 deletions tests/test_types.py
Expand Up @@ -5308,6 +5308,16 @@ def my_function(y: type_hint):
assert my_function('2') == "'2'"


def test_skip_validation_model_reference():
class ModelA(BaseModel):
x: int

class ModelB(BaseModel):
y: SkipValidation[ModelA]

assert ModelB(y=123).y == 123


def test_skip_validation_serialization():
class A(BaseModel):
x: SkipValidation[int]
Expand Down

0 comments on commit 9c03680

Please sign in to comment.