<#1243 fix(types): handle default_factory fields w...
# flyte-github
a
#1243 fix(types): handle default_factory fields when reconstructing untagged outputs Pull request opened by samhita-alla Reconstructing a Pydantic/dataclass output from its schema (when the original class isn't available) crashed for untagged outputs whose schema has
default_factory
fields:
Copy code
TypeError: non-default argument '<field>' follows default argument
Pydantic omits the
default
key from the JSON schema for
default_factory
fields, so they were handed to
make_dataclass
without a default. Whenever a defaulted field happened to precede one in the (hash-randomized) schema order,
make_dataclass
raised intermittently. Earlier SDKs instead dropped these fields silently (lossy reconstruction). Regression from #1171, which stopped dropping non-required fields but left
default_factory
fields without a default on the dataclass path. The tagged Pydantic path (
create_model
, no field-ordering constraint) was already correct; this only affects the untagged path that older, pre-tagging producers' outputs take. Fix Give every non-required field a default during reconstruction, choosing a faithful one by shape: •
list
→
[]
,
dict
→
{}
• nested model (no-arg constructible) → a constructed instance (recursive) • everything else →
Optional[...] = None
Fixes the crash and restores full-fidelity reconstruction (no dropped fields) on the untagged path. Test plan • Added regression tests covering all field orderings, all-optional schemas, collection defaults, and nested models (constructed instance + fallback to
None
when the nested model has a required field). • Confirmed the new tests fail on the pre-fix code and pass after. • Full type-engine suite passes. Fixes https://linear.app/unionai/issue/ENG26-756/make-dataclass-ordering-crash-for-untagged-pydantic-struct-outputs, https://linear.app/unionai/issue/ENG26-791/tagged-pydantic-path-reconstructs-default-factory-fields-as-required 🤖 Generated with Claude Code flyteorg/flyte-sdk