Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.2k
Only fetch__pydantic_core_schema__
from the current class during schema generation#10518
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@@ -813,9 +813,12 @@ def _generate_schema_from_property(self, obj: Any, source: Any) -> core_schema.C | |||
source, CallbackGetCoreSchemaHandler(self._generate_schema_inner, self, ref_mode=ref_mode) | |||
) | |||
elif ( | |||
(existing_schema := getattr(obj, '__pydantic_core_schema__', None)) is not None | |||
hasattr(obj, '__dict__') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We could also check for__slots__
but there's no such type with a__pydantic_core_schema__
property as of today, so I'm keeping things simple here by only checking for__dict__
3f853bb
to8dff26d
Comparecloudflare-workers-and-pagesbot commentedSep 30, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Deploying pydantic-docs with |
Latest commit: | 8dff26d |
Status: | ✅ Deploy successful! |
Preview URL: | https://1988b6bf.pydantic-docs.pages.dev |
Branch Preview URL: | https://gen-schema-from-property-dic.pydantic-docs.pages.dev |
codspeed-hqbot commentedSep 30, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
CodSpeed Performance ReportMerging#10518 willnot alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nice find!
4bcbaa1
intomainUh oh!
There was an error while loading.Please reload this page.
In some cases, the core schema of a class is not the right one:
Until now, we had the
existing_schema.get('cls', None) is obj
check to avoid incorrectly using the core schema in this case. However, this doesn't work if the core schema is of typedefinitions
, in which caseexisting_schema.get('cls', None) is obj
isFalse
even though it is the correct schema. This was found during the ns refactor.Change Summary
Related issue number
Checklist