<#1171 feat: coerce plain dicts into BaseModel/dat...
# flyte-github
a
#1171 feat: coerce plain dicts into BaseModel/dataclass inputs for flyte.run Pull request opened by AdilFayyaz Motivation Callers want to launch a task whose input is a Pydantic BaseModel/dataclass by passing a plain dict — including a partial dict where omitted fields fall back to defaults — and without importing the input class (so the task definition and client can live in separate repos). The CLI already did this in its param layer, but the Python flyte.run path didn't: Pydantic inputs crashed (AttributeError: model_dump_json) and dataclass inputs were passed through unvalidated. The decoupled (reconstructed-type) path had additional latent bugs, including the original KeyError: 'title' on dict[str, str] | None. Summary • Coercion at the type-engine layer (_type_engine.py): PydanticTransformer.to_literal now model_validates a dict; DataclassTransformer.to_literal decodes a dict (validated, defaults applied) instead of dumping it raw. Failures raise TypeTransformerFailedError so Union variants fall through. • Partial inputs: DataclassTransformer.assert_type allows fields with defaults to be omitted, only recurses into nested dataclass fields, and skips the early type check when the annotation isn't a concrete type (handles from future import annotations). • Decoupled / reconstructed types: _create_pydantic_model_from_schema and generate_attribute_list_from_dataclass_json_mixin now reconstruct all fields (not just required), so defaulted fields survive; the dataclass anyOf branch handles dict-shaped variants and no longer KeyErrors on a missing title (fixes the original dict[str, str] | None crash). • Example + tests: added examples/basics/types/dict_to_model_inputs.py and 16 new unit tests covering full/partial/nested/optional dicts, decoupled reconstruction, and the dict[str,str] | None shape (Pydantic + dataclass, incl. stringized annotations). Test Plan • pytest tests/flyte/type_engine → 414 passed (incl. 16 new coercion tests). • Full pytest tests/flyte → 2710 passed; the 18 failures are pre-existing infra tests (S3, remote roundtrip, obstore, serve) — identical count on a clean tree. • Run the example end-to-end: python examples/basics/types/dict_to_model_inputs.py — confirms full dict, minimal dict (defaults filled), arg override, and dataclass input all succeed. • Decoupled check: reconstruct the type from schema via guess_python_type (no original class) and convert a minimal dict — defaults fill for both Pydantic and dataclass, including dict[str, str] | None. flyteorg/flyte-sdk