<#4502 [BUG] Running condition locally results in ...
# flytekit
c
#4502 [BUG] Running condition locally results in weird behavior Issue created by guyarad ### Describe the bug Following the documentation for condionals, testing it locally resulted in odd behavior. The code added below, when executed locally simply by
python merge_sort.py
, results in an error. When the workflow is submitted to the Flyte sandbox environment, this does not reproduce. Code should run as-is. import typing from typing import Tuple from flytekit import conditional, dynamic, task, workflow @task def split(numbers: typing.List[int]) -> Tuple[typing.List[int], typing.List[int], int, int]: return ( numbers[0: int(len(numbers) / 2)], numbers[int(len(numbers) / 2):], (int(len(numbers) / 2)), (int(len(numbers)) - int(len(numbers) / 2)), ) @task def merge(sorted_list1: typing.List[int], sorted_list2: typing.List[int]) -> typing.List[int]: result = [] while len(sorted_list1) > 0 and len(sorted_list2) > 0: if sorted_list1[0] < sorted_list2[0]: result.append(sorted_list1.pop(0)) else: result.append(sorted_list2.pop(0)) result.extend(sorted_list1) result.extend(sorted_list2) return result @task def sort_locally(numbers: typing.List[int]) -> typing.List[int]: if len(numbers) > 5: raise RuntimeError('ahhhh too large') return sorted(numbers) @dynamic def merge_sort_remotely(numbers: typing.List[int], run_local_at_count: int) -> typing.List[int]: split1, split2, new_count1, new_count2 = split(numbers=numbers) sorted1 = merge_sort(numbers=split1, numbers_count=new_count1, run_local_at_count=run_local_at_count) sorted2 = merge_sort(numbers=split2, numbers_count=new_count2, run_local_at_count=run_local_at_count) return merge(sorted_list1=sorted1, sorted_list2=sorted2) @workflow def merge_sort(numbers: typing.List[int], numbers_count: int, run_local_at_count: int = 5) -> typing.List[int]: return ( conditional("terminal_case") .if_(numbers_count <= run_local_at_count) .then(sort_locally(numbers=numbers)) .else_() .then(merge_sort_remotely(numbers=numbers, run_local_at_count=run_local_at_count)) ) if name == "__main__": sorted_list = merge_sort(numbers=list(range(20, 0, -1)), numbers_count=20) print(f"Running Merge Sort Locally...{sorted_list}") CC: @samhita-alla ### Expected behavior Since the default for "sorting locally" is 5, we should never have a list of more than 5 in
sort_locally
function, so no runtime error should happen. ### Additional context to reproduce No response ### Screenshots No response ### Are you sure this issue hasn't been raised already? • Yes ### Have you read the Code of Conduct? • Yes flyteorg/flyte