https://prefect.io logo
Title
l

Leo Kacenjar

01/26/2023, 10:19 PM
Hello, we are in the process of porting our Prefect 1 flows to 2. There are several places that we used to get the flow name from context. Based on some articles like this. It seems like it may still be possible. However, when I call the suggested methods, I don't see flow name available. Looking at the porting guide I don't see that flow name is available in the "Example Output". Also a community member seems to be having the same problem in the comments below. Is there any way to get the flow name contextually during a run in Prefect 2? I'm running my flows locally in a docker container that matches our production environment with a fresh pull of
prefecthq/prefect:2-latest
Thanks!
z

Zanie

01/26/2023, 10:23 PM
prefect.context.get_run_context().flow_run.name
should do it — we don’t expose great ways to customize the name itself though yet!
l

Leo Kacenjar

01/26/2023, 10:26 PM
Huh, that seems like what I need. When I execute my flow, I get an error like:
AttributeError: 'TaskRunContext' object has no attribute 'flow_run'
z

Zanie

01/26/2023, 10:26 PM
Ah so the task run context doesn’t contain flow run information at this time
I’d call it in a flow and pass the value down to the task if relevant
l

Leo Kacenjar

01/26/2023, 10:26 PM
Ahh ok. I'll give that a shot.
Ok, that gets me the dynamic animal-themed name, but not the name that we gave the flow.
I suppose I can just hard code it and pass it down from the flow.
z

Zanie

01/26/2023, 10:30 PM
The flow is different than the flow run in this case
I believe the flow is in the context too though
get_run_context().flow.name
🙌 1
l

Leo Kacenjar

01/26/2023, 10:31 PM
Ohh, that gets it! Thanks.
I appreciate the help.