-
Notifications
You must be signed in to change notification settings - Fork 292
add left_to_right
union mode
#889
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
@@ -2473,6 +2474,7 @@ def union_schema( | |||
custom_error_type: str | None = None, | |||
custom_error_message: str | None = None, | |||
custom_error_context: dict[str, str | int] | None = None, | |||
mode: Literal['smart', 'left_to_right'] | None = None, |
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.
Would this be better if it was called union_mode
in the schema as well, or does it not matter if it differs from Field(union_mode="...")
?
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 think it doesn't matter, I'm okay either way, would lean toward the way you've done it here though unless the other way meaningfully simplified things on the pydantic side, which I'm not expecting it to do.
bca9d31
to
61df24e
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #889 +/- ##
==========================================
- Coverage 93.79% 93.74% -0.05%
==========================================
Files 105 105
Lines 15252 15333 +81
Branches 25 25
==========================================
+ Hits 14305 14374 +69
- Misses 941 953 +12
Partials 6 6
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
CodSpeed Performance ReportMerging #889 will degrade performances by 12.15%Comparing Summary
Benchmarks breakdown
|
please review |
Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
Change Summary
Adds a
left_to_right
union mode which allows for V1-style union validation, for cases when V2 smart mode is problematic.The related issue linked below suggested a
dumb_union
flag but I think it's better to take mode as a string to give us space to invent new strategies backwards-compatibly if we need to.I assume that we'll expose this in pydantic as
Field(union_mode="left_to_right")
.Related issue number
pydantic/pydantic#7097 (comment)
Checklist
pydantic-core
(except for expected changes)Selected Reviewer: @samuelcolvin