Fix tagged unions multiple processing in submodels#6340
Merged
adriangb merged 3 commits intopydantic:mainfrom Jul 1, 2023
vadim-su:fix_tagged_unions_in_submodels
Merged
Fix tagged unions multiple processing in submodels#6340adriangb merged 3 commits intopydantic:mainfrom vadim-su:fix_tagged_unions_in_submodels
adriangb merged 3 commits intopydantic:mainfrom
vadim-su:fix_tagged_unions_in_submodels
Conversation
Contributor
Author
|
please review |
1 task
dmontagu
reviewed
Jul 1, 2023
| union_model: UnionModel | ||
|
|
||
| class TestModel(BaseModel): | ||
| submodel: Union[SubModel1, SubModel2] |
Contributor
There was a problem hiding this comment.
@suharnikov any chance you could add a bit of validation here just to make sure it actually behaves correctly during validation, not just that it stops erroring while building the schema
Member
There was a problem hiding this comment.
Also a json schema check would be good
adriangb
approved these changes
Jul 1, 2023
Member
|
We need to start requiring change files. |
Contributor
Author
|
I missed all the fun 😅 |
|
@samuelcolvin / @dmontagu Is there going to be a minor release sometime soon with this fix? I use nested discriminated unions pretty extensively in my API so this is currently blocking my upgrade to v2 EDIT: This is now in 2.0.3, thanks all! |
1 task
a10y
added a commit
to IntrinsicLabsAI/intrinsic-model-server
that referenced
this pull request
Jul 6, 2023
## Bump to Pydantic v2 This PR brings the repo onto Pydantic v 2.0.2 and FastAPI v 0.100.0-beta3 (0.100.0 is expected to cut by EOW and this is the last beta release). * Rework how we do custom tagged union types * The new paradigm for this involves extending a `RootModel` generic type from pydantic, which I find a bit gross but it is the new supported way to do this so 🤷 * Use all of the new `model_` methods that were renamed for AFAICT no particular reason * Bump the FE generated types to use the new SemVer type alias in the FE. - [X] Blocked until we get a new release pydantic/pydantic#6340 (comment)
Closed
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Summary
In some cases like that:
apply_discriminatorsfunction could process tagged-unions because thetagged-unioncontainsdiscriminator, but doesn't take that the schema was processed in another model. I excluded tagged-unions from the recursive processing.I'm not sure about the place of the fix. Possibly a better place for this is
_ApplyInferredDiscriminator.applypydantic/pydantic/_internal/_discriminated_union.py
Lines 154 to 160 in 15d5e0b
Related issue number
Fix #6339
Checklist
changes/<pull request or issue id>-<github username>.mdfile added describing change(see changes/README.md for details)
Selected Reviewer: @lig