-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix tagged unions multiple processing in submodels #6340
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
Fix tagged unions multiple processing in submodels #6340
Conversation
|
please review |
| union_model: UnionModel | ||
|
|
||
| class TestModel(BaseModel): | ||
| submodel: Union[SubModel1, SubModel2] |
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.
@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
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.
Also a json schema check would be good
|
We need to start requiring change files. |
|
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! |
## 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)
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