Conversation
Deploying with
|
| Latest commit: |
84d6f6d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://691f9560.pydantic-docs2.pages.dev |
| Branch Preview URL: | https://dh-union-mode.pydantic-docs2.pages.dev |
29f26ff to
84d6f6d
Compare
davidhewitt
commented
Aug 16, 2023
Comment on lines
+509
to
+510
| To revert to the non-short-circuiting left-to-right behavior of V1, annotate the union with `Field(union_mode='left_to_right')`. | ||
| See [Union Mode](./usage/types/unions.md#union-mode) for more details. |
Collaborator
Author
There was a problem hiding this comment.
I'm not an expert on V1's union validation, this statement may not be true. I thought it might be worth calling out this or something similar here in the migration guide.
dmontagu
approved these changes
Aug 16, 2023
|
@davidhewitt Thank you! This will greatly ease our transition to Pydantic V2! |
|
Hi, just found this gem while migrating to V2. Is there a way to make this behavior as default..? |
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
Adds a new
Fieldoption,union_mode, which can be used to alter the union validation. At present, there are only two options:smart(the default), which is equivalent to the current V2 behaviourleft_to_right, which is just simple left-to-right validation, first success wins, like V1This option can be used to opt out of smart union validation in cases when users want more easily understandable results.
In #7097 (comment) we suggested a
dumb_union=Trueboolean flag. In further discussion offline I raised the idea that using a string setting here (while a touch more verbose) is more descriptive and also gives us space to add more options backwards-compatibly later.Related issue number
Related #7097
Related #7110
Checklist