File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 1414import inspect
1515import warnings
1616from abc import ABC , abstractmethod
17+ from contextlib import suppress
1718from dataclasses import dataclass
1819from typing import (
1920 TYPE_CHECKING ,
4041 from pydantic .generics import GenericModel
4142
4243
44+ try :
45+ from pydantic import PydanticUndefinedAnnotation # type: ignore[attr-defined]
46+ except ImportError :
47+
48+ class PydanticUndefinedAnnotation (Exception ): # type: ignore[no-redef]
49+ pass
50+
51+
4352from typing_extensions import Self , TypeGuard , deprecated
4453
4554from .types import Cursor , GreaterEqualZero , ParamsType
@@ -158,7 +167,10 @@ def __pydantic_init_subclass__(cls, **kwargs: Any) -> None:
158167 for name , alias in cls .__model_aliases__ .items ():
159168 cls .model_fields [name ].serialization_alias = alias
160169
161- cls .model_rebuild (force = True )
170+ # rebuild model only in case if customizations is present
171+ if cls .__model_exclude__ or cls .__model_aliases__ :
172+ with suppress (PydanticUndefinedAnnotation ):
173+ cls .model_rebuild (force = True )
162174
163175 def __init_subclass__ (cls , ** kwargs : Any ) -> None :
164176 try :
You can’t perform that action at this time.
0 commit comments