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 incorrect 'smart' union discrimination #1844
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1844 +/- ##
=======================================
Coverage 91.20% 91.20%
=======================================
Files 75 75
Lines 4629 4629
=======================================
Hits 4222 4222
Misses 407 407
Flags with carried forward coverage won't be shown. Click here to find out more.
|
e2e587a
to
bd30d17
Compare
352f6d2
to
4105648
Compare
- Add tests that enums are properly deserialzed for links and links
980c1ff
to
e5f4e3a
Compare
My thoughts 😉: Using I think it can be implemented in |
Welp - you can say "I told you so". To be more explicit, it seems to me the reason for not being able to do this is that we cannot know if the type annotation is a So yeah. Either it has to be set explicitly in every place where we want it used - or we can create another wrapper However, it's worth investigating whether this needs to be propagated down to entry-specific models as well to ensure |
I lost an hour to trying to hack this too, probably best to avoid digging in pydantic internals for a while...
Yeah, I did a search for anywhere we're doing a union with a |
Closes #1843.
pydantic v2 made "smart" union discrimination by default, which seems to favour dicts over models.
For now I've made it so that any
Union[Model, dict[str, Any]]
fields use the newly-added workaround in pydantic v2.3,union_mode = 'left_to_right'
. Unfortunately we can't set this globally at the level ofStrictField
as it crashes out in schema generation if the schema type is not'union'
. I might make an issue about this on pydantic.@CasperWA you may have thoughts -- will probably merge but feel free to do a post-review!