4

Hi everyone I was trying to create a flow using prefect for python but I get the error TypeError: 'fn' must be callable, I already install all the packages and I have tried in different IDE like vs code and colab but the result is the same.

the code is:

from prefect import task, Flow


@task()
def load():
    print("Loading data")

with Flow("Hello-world") as flow:
    load()

flow.run() 


#ERROR
TypeError: 'fn' must be callable

I tried changing the code to this but I get a different error:

from prefect import task, Flow


@task()
def load():
    print("Loading data")

with Flow(name = "Hello-world") as flow:
    load()

flow.run() 

#ERROR
TypeError: Flow.__init__() missing 1 required positional argument: 'fn'
Hardroco
  • 41
  • 2

2 Answers2

3

In Prefect 2.0 or major, we need to create a flow how in the next example:

import pandas as pd
import numpy as np

from prefect import flow, task, Flow

@task
def extract():
    pass

@task
def transform():
    pass

@task
def load():
    pass

"""
with Flow("ETL Test") as flow:
    extract()
    transform()
    load()

flow.run()
"""

@flow
def flow_caso():
    extract()
    transform()
    load()

flow_caso()

In the comments you can see how we can create a flow in Prefect with version minor to 2.0.0, but in versions major you need to create a function with the decorator @flow.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 12 '22 at 11:55
2

I believe you are trying to run a Prefect 1.0 flow using the Prefect 2.0 package.

I was able to run your example fine using prefect==1.2.4 and I was able to reproduce your error using prefect==2.0.0

Here's what your example could look like using prefect>=2.0.0:

from prefect import flow, task

@task
def load():
   print("Loading data")

@flow(name="Hello-world")
def my_flow():
   load()

if __name__ == "__main__":
   my_flow()

Here are some docs on running prefect 2.0 flows

Stoat
  • 51
  • 4