The "preserve the type of the input whenever possible" union handling is inconsistent #7097
Open
1 task done
Labels
bug V2
Bug related to Pydantic V2
unconfirmed
Bug not yet confirmed as valid/applicable
V3
Under consideration for V3
Initial Checks
Description
Code that relies on the strict left-to-right behavior of union validation/parsing is broken in V2, with no available workaround. Not only that, but the subtle change creates inconsistencies where identical data in python or JSON form parses differently. In the example code, all of those would have parsed as UUIDs in V1 (behavior that our code relies on), but now, it parses as string in certain scenarios, but not in others.
It is difficult to migrate with this highly inconsistent and frankly baffling behavior. Using unions like the one in the example with FastAPI as path parameters or query parameters used to be a useful way to detect UUIDs, but now, FastAPI always returns a string.
Example Code
Python, Pydantic & OS Version
Selected Assignee: @dmontagu
The text was updated successfully, but these errors were encountered: