https://prefect.io logo
c

Chu

08/02/2022, 2:30 PM
what does this error implies:
Copy code
TypeError: `fn` must be callable
I’m calling a task inside a With Flow statement, and the Task should return me a list of strings
1
n

Nate

08/02/2022, 2:41 PM
Hi @Chu, what is the output of
prefect version
? I suspect you're writing prefect 1.0 code using
prefect>=2.0
c

Chu

08/02/2022, 2:45 PM
it’s 1.2.2
forget this question, I remove the @task decorator
n

Nate

08/02/2022, 2:46 PM
okay - is there anything else you need help with?
c

Chu

08/02/2022, 2:48 PM
What are the Parameter() call returns, a JSON object?, Is there a method I can deserialize it to its original input, for example:
Copy code
params = Parameter("ids", default=['a','b','c'])
like to deserialize
params
to [‘a’,‘b’,‘c’]
n

Nate

08/02/2022, 2:55 PM
in Prefect 1.0, the
Parameter
object is a special type of task, so within the
with Flow(...) as flow:
block (called the flow context) the return of your task will be of type
prefect.tasks.core.function.FunctionTask
and you cannot [sic] access the true value (a list in your case) in the flow context however, when you pass this
Parameter
to a downstream task, you can treat it as a list like you'd expect, for example you could have
Copy code
@task(log_stdout=True)
def my_downstream_task(my_params: List[str]):
    print(type(my_params))
    print(my_params)

    # do other things with your params

with Flow('my flow') as flow:
    params = Parameter("ids", default=['a','b','c'])

    my_task_result = my_downstream_task(params)
    
if __name__ == "__main__":
    flow.run()
c

Chu

08/02/2022, 2:55 PM
I think I can get it by calling
params.default
it will return me the actual input
n

Nate

08/02/2022, 2:58 PM
oh, wow I didn't know that was there - nice find!
c

Chu

08/02/2022, 3:06 PM
this approach is pretty helpful when we scheduled a mapped flow run, where we want to input a list as mapping parameter but other params are not mapped this trick can enable us to have a flow of flow of flows architecture with high visibility by scheduling the grandparent flow and sending parameters in Prefect UI
n

Nate

08/02/2022, 3:16 PM
that's awesome - thanks for teaching me something today! I would encourage you to check out prefect 2.0 at some point, since you can interact directly with task results in all contexts / scopes of your code and you can arbitrarily nest flow calls - here are some docs on subflows in 2.0 if you're interested!
🙌 1
c

Chu

08/02/2022, 3:18 PM
For sure, we are in a transition to Prefect 2.0, and certain Prefect 2.0 will do better than 1.0, but still glad we find some workaround in 1.0 (to make it work) and hope this may help others in the community
👏 1
24 Views