Conrad Dobberstein
02/28/2023, 10:38 AMmy_flow
takes an iterable of strings as the first parameter. When calling the flow with an iterator, its first element is missing inside the flow run. This also applies when calling the flow with a list and enabling validate_parameters
. Is this a bug, or am I missing something obvious here? I'm on the latest version of Prefect, i.e. Prefect 2.8.3.
from collections.abc import Iterable
import prefect
@prefect.flow
def my_flow(texts: Iterable[str]) -> None:
print(f"{type(texts)=}")
print(f"{list(texts)=}")
if __name__ == "__main__":
# type(texts)=<class 'list_iterator'>
# list(texts)=['World', '!']
my_flow.with_options(validate_parameters=True)(["Hello", "World", "!"])
# type(texts)=<class 'list_iterator'>
# list(texts)=['World', '!']
my_flow.with_options(validate_parameters=False)(iter(["Hello", "World", "!"]))
# type(texts)=<class 'list'>
# list(texts)=['Hello', 'World', '!']
my_flow.with_options(validate_parameters=False)(["Hello", "World", "!"])
Mason Menges
02/28/2023, 7:05 PMConrad Dobberstein
03/01/2023, 11:44 AMimport prefect
@prefect.flow
def my_flow(numbers):
print(f"{type(numbers)=}")
print(f"{list(numbers)=}")
if __name__ == "__main__":
# type(numbers)=<class 'generator'>
# list(numbers)=[]
my_flow((x for x in range(3)))
# type(numbers)=<class 'list_iterator'>
# list(numbers)=[1, 2]
my_flow(iter([0, 1, 2]))