You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A flytekit.core.promise.Promise functions as an infinite Iterator, returning the same object over and over again.
Promises are easily used in an unsupported way. E.g. given a task that returns a list of values, a user might be tempted to extend() an existing list with the task's return.
See below example of how such a situation might occur.
Below code will not fail nicely, but will steadily grow out_list.
Expected behavior
Consider raising StopIteration after its elements have been exhausted.
related: #3508
I see that the solution proposed for #5164 (comment) would solve this issue as well:
Python calls the iter function in this case, which then infinitely loops, until the process runs out of memory. The fix is just to disallow calling this on a promise.
Additional context to reproduce
from flytekit import dynamic, task, workflow
@task
def my_task(inp: int) -> list[int]:
return [inp, inp]
@dynamic
def my_dynamic() ->list[int]:
out_list = list()
for i in range(2):
out_this = my_task(inp=i)
out_list.extend(out_this)
return out_list
@workflow
def my_workflow() -> list[int]:
result = my_dynamic()
return result
if __name__ == "__main__":
my_workflow()
Screenshots
No response
Are you sure this issue hasn't been raised already?
Yes
Have you read the Code of Conduct?
Yes
The text was updated successfully, but these errors were encountered:
The behavior you're encountering with Promise objects in Flyte is due to their design to act as placeholders for values that are not yet computed, rather than iterable objects. The issue you described is similar to a known problem where iterating over a Promise does not behave as expected because Python's __iter__ method is called, which can lead to infinite loops or memory issues if not handled correctly. This is documented in a related Flyte issue where iterating over a list of FlyteFile objects within a dynamic task caused infinite loops and memory growth (Flyte issue #5164).
Promise objects are not designed to be directly iterable. The correct approach is to ensure that the task outputs are fully materialized before attempting operations like extending a list. This can be managed by structuring your workflows and tasks to handle dependencies and outputs appropriately, ensuring that Promise objects are resolved before such operations.
Would you like a more detailed explanation on how to structure your Flyte tasks and workflows to avoid such issues?
Describe the bug
A
flytekit.core.promise.Promise
functions as an infinite Iterator, returning the same object over and over again.Promise
s are easily used in an unsupported way. E.g. given atask
that returns a list of values, a user might be tempted to extend() an existing list with the task's return.See below example of how such a situation might occur.
Below code will not fail nicely, but will steadily grow
out_list
.Expected behavior
Consider raising
StopIteration
after its elements have been exhausted.related: #3508
I see that the solution proposed for #5164 (comment) would solve this issue as well:
Additional context to reproduce
Screenshots
No response
Are you sure this issue hasn't been raised already?
Have you read the Code of Conduct?
The text was updated successfully, but these errors were encountered: