-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Improve error handling for in-evaluable refs for discriminator application #10440
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CodSpeed Performance ReportMerging #10440 will not alter performanceComparing Summary
|
Deploying pydantic-docs with
|
| Latest commit: |
113414a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b1d5d5ab.pydantic-docs.pages.dev |
| Branch Preview URL: | https://disc-fix-alias.pydantic-docs.pages.dev |
| @@ -466,7 +466,6 @@ def populate_defs(core_schema: CoreSchema, json_schema: JsonSchemaValue) -> Json | |||
| core_ref = CoreRef(core_schema['ref']) # type: ignore[typeddict-item] | |||
| defs_ref, ref_json_schema = self.get_cache_defs_ref_schema(core_ref) | |||
| json_ref = JsonRef(ref_json_schema['$ref']) | |||
| self.json_to_defs_refs[json_ref] = defs_ref | |||
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.
This is done in the self.get_cache_defs_ref_schema(core_ref) call, so no reason to do that here.
pydantic/json_schema.py
Outdated
| while '$ref' in choice: | ||
| assert isinstance(choice['$ref'], str) | ||
| choice = self.get_schema_from_definitions(JsonRef(choice['$ref'])) or {} | ||
| choice = self.resolve_schema_to_update(choice) |
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.
This function handles the above removed logic more gracefully, with an intuitive error.
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.
I'll try to do a deep dive in the JSON Schema generation process to see what this is about, I'm guessing it is indeed pretty similar to the core schema gen process
|
Note from my conversation with @adriangb - we could alternatively do a first pass to collect all defs |
This was supposed to close #8271, but right now it just improves the associated error.
My current hunch is that we need to do an apply discriminators step at the end of json schema building, like we do for core schemas, if we want this to work 😭. Not sure how worth the investment that is, at the moment.
I'd also be open to more creative solutions for evaluating refs for which we have not yet generated the schemas. Probably a good conversation to have with @Viicos and @adriangb.
MRE, at the moment: