File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -617,9 +617,11 @@ def model_rebuild(
617
617
return None
618
618
619
619
for attr in ('__pydantic_core_schema__' , '__pydantic_validator__' , '__pydantic_serializer__' ):
620
- if attr in cls .__dict__ :
620
+ if attr in cls .__dict__ and not isinstance ( getattr ( cls , attr ), _mock_val_ser . MockValSer ) :
621
621
# Deleting the validator/serializer is necessary as otherwise they can get reused in
622
- # pydantic-core. Same applies for the core schema that can be reused in schema generation.
622
+ # pydantic-core. We do so only if they aren't mock instances, otherwise — as `model_rebuild()`
623
+ # isn't thread-safe — concurrent model instantiations can lead to the parent validator being used.
624
+ # Same applies for the core schema that can be reused in schema generation.
623
625
delattr (cls , attr )
624
626
625
627
cls .__pydantic_complete__ = False
You can’t perform that action at this time.
0 commit comments