<#3294 [BUG] Local testing using optional dicts wi...
# flyte-github
c
#3294 [BUG] Local testing using optional dicts with optional values does not work Pull request opened by machichima ## Tracking issue Closes flyteorg/flyte#6474 ## Why are the changes needed? When running task locally, using optional list values types (i.e.
dict[str, list[str] | None] | None
) will cause error. However, when running such task on the cluster it works ## What changes were proposed in this pull request? Error occurs when we call
_are_types_castable(List[Sample], Union)
. In original code, the check for collection type will directly return
False
, which indicates that
List[Sample]
is not castable to
Union[List[Sample], None]
, leading to the error. In this PR, I deal with
union_type
first in
_are_types_castable
function to overcome this problem. ## How was this patch tested? Test with the following script. See result in Screenshots section. from flytekit import task @task def complex_task(data: dict[str, list[str] | None] | None) -> dict[str, list[str] | None] | None: return data def test_complex_task() -> dict[str, list[str] | None] | None: return complex_task(data={"key": ["value1", "value2"]}) if name == "__main__": print(test_complex_task()) ### Setup process ### Screenshots Successfully execute the above script: [image](https://private-user-images.githubusercontent.com/60069744/465736336-ebc79936-792b-4d27-bf1c-edf17a733579.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTI2NTMwMjUsIm5iZiI6MTc1MjY1MjcyNSwicGF0aCI6Ii82MDA2OTc0NC80NjU3MzYzMzYtZWJjNzk5MzYtNzkyYi00ZDI3LWJmMWMtZWRmMTdhNzMzNTc5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA3MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNzE2VDA3NTg0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWI0ZWZjMmI3YzAwYWU0ZmZkOThjZDhkMTEyYzYwMTM0MTIzNjE1YTY3YjgzNTI4MTBiZjUwNmQ5YWJhODZjNWYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.X0csHzNdgBNGPpUVAiQtNQB68BJ4IRSRfh7zS7Xm5S8) ## Check all the applicable boxes • I updated the documentation accordingly. • All new and existing tests passed. • All commits are signed-off. ## Related PRs ## Docs link https://bito.ai#summarystart| ### Summary by Bito This pull request fixes a bug in type casting for optional dictionary values, ensuring the
_are_types_castable
function properly handles union types. It also includes minor code cleanup to enhance error handling in type transformations. flyteorg/flytekit