<#664 Generalize custom type detection in nested P...
# flyte-github
a
#664 Generalize custom type detection in nested Pydantic models Pull request opened by AdilFayyaz ## Summary: • When
guess_python_type
reconstructs a Python type from a Flyte LiteralType (JSON schema), nested custom types with registered TypeTransformers were being rebuilt as generic dataclasses instead of being recognized as their original types. This is because the schema reconstruction code had hardcoded checks for File and Dir only and never consulted TypeEngine._REGISTRY for other registered types. • Added
schema_match()
method to TypeTransformer that auto-matches for BaseModel subclasses by comparing JSON schema fingerprints (title, type, required fields). No user override needed, registering a transformer for BaseModel subclass is sufficient. • Added
_match_registered_type_from_schema()
helper that iterates all registered transformers to find a match. • Replaced all hardcoded
File.schema_match()/Dir.schema_match()
call sites in
generate_attribute_list_from_dataclass_json_mixin
and
_get_element_type
with the generalized helper. This also fixes a bug where File/Dir were not detected when referenced via $ref in the schema. ## Test Plan • pytest
tests/flyte/type_engine/pydantic/test_custom_type_in_nested_pydantic.py
10 new tests covering
_match_registered_type_from_schema
(match, no match, File, Dir), guess_python_type structure verification (direct, List, Dict, nested List, mixed with File+Dir), and default schema_match behavior flyteorg/flyte-sdk