Commit 76597a5
committed
fix: Handle list[Model], dict[str, Model] and Optional[Model] in nested type detection
The nested schema type detection from PR #426 did not resolve $ref for
list items, dict additionalProperties, or anyOf (Optional) fields.
This caused KeyError or incorrect type inference when using Pydantic or
dataclass models with fields like list[NestedModel], dict[str, NestedModel],
or Optional[NestedModel].
Changes:
- Add $ref resolution to _get_element_type for centralized handling
- Extract _resolve_ref, _resolve_property_type, _resolve_single_type,
and _resolve_typed_property helpers to eliminate duplicated $ref logic
- Properly validate Optional via anyOf (check len==2 and null second element)
- Add default=None for optional fields not in required list
- Include optional properties in property_order so fields with defaults
are not skipped during schema traversal
- Extend __init__ wrapper to convert list[dict] and dict[str, dict]
to their respective nested types
Ref: flyteorg/flyte#6887
Signed-off-by: André Ahlert <andre@aex.partners>1 parent 28396f2 commit 76597a5
File tree
2 files changed
+494
-125
lines changed- src/flyte/types
- tests/flyte/type_engine/pydantic
2 files changed
+494
-125
lines changed
0 commit comments