Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0a21ab1

Browse files
authored
Do not delete mock validator/serializer inmodel_rebuild() (#11890)
1 parente92ad79 commit0a21ab1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

‎pydantic/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,11 @@ def model_rebuild(
620620
cls.__pydantic_complete__=False
621621

622622
forattrin ('__pydantic_core_schema__','__pydantic_validator__','__pydantic_serializer__'):
623-
ifattrincls.__dict__:
623+
ifattrincls.__dict__andnotisinstance(getattr(cls,attr),_mock_val_ser.MockValSer):
624624
# Deleting the validator/serializer is necessary as otherwise they can get reused in
625-
# pydantic-core. Same applies for the core schema that can be reused in schema generation.
625+
# pydantic-core. We do so only if they aren't mock instances, otherwise — as `model_rebuild()`
626+
# isn't thread-safe — concurrent model instantiations can lead to the parent validator being used.
627+
# Same applies for the core schema that can be reused in schema generation.
626628
delattr(cls,attr)
627629

628630
if_types_namespaceisnotNone:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp