You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can workaround the situation here by setting extra = 'forbid' in your model configuration. What is happening is that the A type is ignoring the field for B and then successfully validates by using the defaults.
I agree this is not ideal, and I've been working on improvements to union type inference in pydantic/pydantic-core#867. I think the changes I have in mind would not solve this case.
Initial Checks
Description
When using type coercion with a union and defaults, pydantic chooses the first type rather the one where a value has been set.
For now I am using validators as a workaround.
Example Code
Python, Pydantic & OS Version
Selected Assignee: @davidhewitt
The text was updated successfully, but these errors were encountered: