Closed MarcBresson closed 3 months ago
@MarcBresson,
Thanks for your question. This is a consequence of pydantic's smart union matching logic, that tries to find the best match out of the possible union candidates. If you'd prefer to always match A
when one
is present, you can use union_mode='right_to_left'
in the config for the zero
field, which will ensure that the first match is the one returned.
Let me know if you have any other questions! :)
Initial Checks
Description
Hello,
I'm building an app and stumbled on a not reliable behaviour of pydantic. Basically, when the input corresponds to multiple base model, the one that is going to be selected in the end will depend on unknown things. See the example below for more context.
Example Code
The following :
will return
but
will return
Python, Pydantic & OS Version