acoustic-carpenter-78188
05/26/2026, 8:08 PMoneOf and a top-level `discriminator`—to Flyte's type engine. It fixes previous issues where such schemas would cause errors, and ensures that union types are correctly roundtripped, validated, and reconstructed. The changes include enhancements to schema parsing, dynamic class generation, and comprehensive regression tests.
Support for Pydantic v2 discriminated unions:
• Updated the type engine to recognize and properly handle JSON schemas with oneOf and a top-level discriminator (as emitted by Pydantic v2 for Annotated[Union[...], Field(discriminator=...)]), ensuring correct type inference and runtime dispatch.
• Added the _DiscriminatedUnion descriptor to capture discriminator metadata and variant mappings, enabling correct dict-to-object conversion during dataclass instantiation.
• Improved handling of optional and list fields containing discriminated unions, so that Optional[...] and List[...] of such types are supported seamlessly.
Testing and documentation:
• Added a comprehensive regression test suite covering schema generation, type inference, correct dispatch on discriminator values, roundtripping through the type engine, and validation using dynamically generated Pydantic models.
• Introduced a new example (examples/basics/types/pydantic_union_types.py) demonstrating end-to-end usage of Pydantic v2 discriminated unions as Flyte task inputs.
These changes ensure that Flyte tasks can now reliably accept and process Pydantic v2 discriminated unions, addressing previous limitations and improving compatibility with modern Pydantic codebases.
flyteorg/flyte-sdkacoustic-carpenter-78188
05/28/2026, 1:48 AM