Hi. I'm new to Prefect and having some trouble und...
# prefect-community
c
Hi. I'm new to Prefect and having some trouble understanding the concept of tasks and task runs. I'm trying to return data from a task, but attempting to print the results of the task only prints out
<Task: fetch_data>
. This is what I'm trying to do:
@task
def fetch_data():
return {"data": "random data"}
with Flow('Get-Data') as flow:
flow.run_config = LocalRun()
data = fetch_data()
<http://logger.info|logger.info>(data)
flow.run()
k
Hey @Carlos Cueto, This is because
<http://logger.info|logger.info>
is logging during the flow build time, not during runtime. Also, your run_config should be outisde the flow
Copy code
with Flow('Get-Data') as flow:
    
    data = fetch_data()
    <http://logger.info|logger.info>(data)

flow.run_config = LocalRun()
So the
with Flow()
builds the DAG and the logger is running during buildtime
c
Thank you Kevin. I'm still a little confused. I think I understand your point. Can you advise how to print the results of
fetch_data
during flow runtime and not build time? Would I be forced to call the
<http://logger.info|logger.info>()
inside a
@task
decorated function? In addition, do you mind explaining the difference between run_config inside the flow vs outside the flow context?
k
Yes exactly use the logger inside the task
The
Copy code
with Flow('Get-Data') as flow:
   ...
build the flow and then the
Copy code
flow.run_config = ...
sets a property. It may work, but there are some edge cases where this will cause some weirdness. The Flow block is really intended to build the DAG
👍 1