Hello! I'm new to prefect and I'm trying to use t...
# prefect-server
a
Hello! I'm new to prefect and I'm trying to use the prefect cli to register my a flow. Every time I run it, it returns with "0 registered." I even tried to register one of the tutorial programs (command: prefect register --project "misc" --path 03_parameterized_etl_flow.py) and it did the same thing. I was able to get one flow to register using the flow.register() method in my script, but I can't get the cli to detect my flows.
k
Hi @Andrew Stewart! Welcome to Prefect. Are you doing this command in the directory with the file?
a
Yes. I'm on Windows if it matters.
k
Could you show me the log? Does it detect nothing? Or detect no flow with changes?
Do you see this:
Copy code
Collecting flows...
======================== 0 registered ========================
or
Copy code
Registering 'unique logger'... Skipped (metadata unchanged)
================== 0 registered, 1 skipped ==================
What Prefect version are you on?
a
I'm on version 0.15.13
k
can you try providing an absolute path?
that’s very weird. might be a bug on windows
z
Can you share the contents of the file you’re passing?
a
Absolute path doesn't work either.
I just discovered "prefect run" doesn't work either, but running the script in python works.
@Zanie I started trying it with some custom flows that I wrote, but right now I'm literally trying to register one of the tutorial files from the docs/github.
z
You are defining your flow in a function then only calling that function if your file is run as a script
So when
prefect run
or
prefect register
look for flows in your file, we do not find them.
You could do something like this instead:
Copy code
def get_flow():
    with Flow("etl") as flow:
        airport = Parameter("airport", default="IAD")
        radius = Parameter("radius", default=200)
    
        reference_data = extract_reference_data()
        live_data = extract_live_data(airport, radius, reference_data)
    
        transformed_live_data = transform(live_data, reference_data)
    
        load_reference_data(reference_data)
        load_live_data(transformed_live_data)
   return flow

flow = get_flow()


if __name__ == "__main__":
    flow.run(airport="DCA", radius=10)
🙌 1
a
OK, thank you! I was writing my own scripts using those tutorial files as a template, so that must be my problem there.
So, you need to have initialized flow objects in the main body of the program for it register them?
k
Yes because it evaluates the script then looks for Flow objects and pulls them for registration
🙏 1