Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix applying SkipValidation to referenced schemas #7381

Merged
merged 1 commit into from
Sep 8, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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