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

Commit8dff26d

Browse files
committed
Only fetch__pydantic_core_schema__ from the current class during schema generation
1 parent01b5929 commit8dff26d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

‎pydantic/_internal/_generate_schema.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,12 @@ def _generate_schema_from_property(self, obj: Any, source: Any) -> core_schema.C
813813
source,CallbackGetCoreSchemaHandler(self._generate_schema_inner,self,ref_mode=ref_mode)
814814
)
815815
elif (
816-
(existing_schema:=getattr(obj,'__pydantic_core_schema__',None))isnotNone
816+
hasattr(obj,'__dict__')
817+
# In some cases (e.g. a stdlib dataclass subclassing a Pydantic dataclass),
818+
# doing an attribute access to get the schema will result in the parent schema
819+
# being fetched. Thus, only look for the current obj's dict:
820+
and (existing_schema:=obj.__dict__.get('__pydantic_core_schema__'))isnotNone
817821
andnotisinstance(existing_schema,MockCoreSchema)
818-
andexisting_schema.get('cls',None)isobj
819822
):
820823
schema=existing_schema
821824
elif (validators:=getattr(obj,'__get_validators__',None))isnotNone:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp