Added support to handle nested Pydantic types#640
Merged
AdilFayyaz merged 2 commits intomainfrom Feb 10, 2026
Merged
Conversation
Signed-off-by: M. Adil Fayyaz <62440954+AdilFayyaz@users.noreply.github.com>
Signed-off-by: M. Adil Fayyaz <62440954+AdilFayyaz@users.noreply.github.com>
pingsutw
approved these changes
Feb 10, 2026
| INACTIVE = "inactive" | ||
|
|
||
|
|
||
| class Inner(BaseModel): |
Member
There was a problem hiding this comment.
For the follow-up, let’s make sure that FlyteFile, FlyteDirectory, and DataFrame also work in the nested model
Collaborator
Author
There was a problem hiding this comment.
Yeah will work on that next.
jeevb
pushed a commit
that referenced
this pull request
Feb 11, 2026
Summary
- Fix `_get_element_type()` in the type engine to correctly resolve
nested and recursive Pydantic types that were previously flattened to
str
- Add $ref resolution so nested models or enums inside containers (List,
Dict) are resolved via $defs lookup instead of defaulting to str
- Rewrite anyOf handling to support $ref variants (e.g.
Optional[Inner]), fixing KeyError: 'type' crashes
- Add recursive array/object branches so nested containers
(List[List[int]], Dict[str, Dict[str, int]]) resolve to their correct
Python types
- Handle null JSON schema type, returning NoneType instead of str
- Add example demonstrating all nested Pydantic type patterns running as
parallel Flyte tasks
Test plan
- pytest
`tests/flyte/type_engine/pydantic/test_nested_structs_in_pydantic.py` :
16 new tests covering -
- Nested arrays: List[List[int]] schema resolution + roundtrip,
List[List[Inner]] roundtrip
- Nested dicts: List[Dict[str, int]] schema + roundtrip, Dict[str,
Dict[str, int]] schema + roundtrip, List[Dict[str, Inner]] roundtrip,
Dict[str, Dict[str, Inner]] roundtrip
- anyOf with $ref: List[Optional[Inner]] schema resolution (no
KeyError), List[Optional[str]] schema resolution, List[Optional[Inner]]
roundtrip via guess_python_type
- null type: {"type": "null"} resolves to NoneType
- Enums in containers: List[ModelWithEnum] roundtrip, Dict[str,
ModelWithEnum] roundtrip
- Complex combined: model with List[List[Inner]], Dict[str, Inner],
List[Dict[str, int]], List[ModelWithEnum], Optional[Inner] roundtrip
with data and with None optional
All previous tests pass
---------
Signed-off-by: M. Adil Fayyaz <62440954+AdilFayyaz@users.noreply.github.com>
Signed-off-by: Jeev B <jeevb@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_get_element_type()in the type engine to correctly resolve nested and recursive Pydantic types that were previously flattened to strTest plan
tests/flyte/type_engine/pydantic/test_nested_structs_in_pydantic.py: 16 new tests covering -All previous tests pass